minitorovaniio
Toto je starší verze dokumentu!
Obsah
Monitorovani IO
- kolik CPU/RAM zere jaky proces se zjisti snadno, napriklad vypisem top
- monitorovani IO je zlozitejsi a dost casto zpomaluje system nejvic
- existuji programy:
- iotop
- atop
- pidstat
- dstat (–topio, –topbio)
- vmstat (-d)
- iostat
- iozone
- sar
iostat
- využívá hodnoty ze sar
- příklad statistik
iostat -d 2 Linux 2.6.18-194.3.1.el5 (nejaky.stroj.nekde.cz) 09/05/2014 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn sda 558.07 236.28 20370.08 1604053205 138289873008 sda1 0.07 0.00 0.36 33698 2429406 sda2 0.00 0.00 0.00 621 0 sda3 2.51 1.59 37.58 10783682 255133504 sda4 555.50 234.68 20332.15 1593234484 138032310098 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn sda 0.50 0.00 12.00 0 24 sda1 0.00 0.00 0.00 0 0 sda2 0.00 0.00 0.00 0 0 sda3 0.00 0.00 0.00 0 0 sda4 0.50 0.00 12.00 0 24 ...
- první statistika je myslím průmer za celý den, další výpisy odpovídají už zadanému časovému období
sar
- ukládá statistiky dlouhodobě (období lze specifikovat)
- příklad:
# sar -b Linux 2.6.18-194.3.1.el5 (nejakej.stroj.nekde.cz) 09/05/2014 12:00:01 AM tps rtps wtps bread/s bwrtn/s 12:10:01 AM 843.15 7.64 835.51 173.54 27131.75 12:20:01 AM 1512.20 15.58 1496.62 255.28 33938.05 12:30:01 AM 1210.95 11.62 1199.33 183.09 29124.69 12:40:01 AM 1069.91 9.31 1060.60 186.96 27125.52 12:50:01 AM 1060.24 9.94 1050.30 157.10 25954.69 01:00:01 AM 1013.24 7.39 1005.85 113.41 27263.05 01:10:01 AM 891.21 7.74 883.47 122.58 25108.18 01:20:01 AM 838.14 7.02 831.12 169.31 25711.26 ..
- výpis obsahuje průměry za 10 minut. Sloupec bread/bwrtn udává, kolik bloků bylo přečteno/zapsáno.
- Bloky jsou pravdepodobne velikosti 512B, prestoze filesystem pouziva bloky vetsi, typicky 4k.
bread/s
Total amount of data read from the devices in blocks per second. Blocks are equiv-
alent to sectors with 2.4 kernels and newer and therefore have a size of 512 bytes.
With older kernels, a block is of indeterminate size.
tune2fs -l /dev/sda4 | grep "Block size" Block size: 4096
UseCase1 (processes read/write old kernel method)
Here’s how you use it. First, get it:
wget http://aspersa.googlecode.com/svn/trunk/iodump
Then turn on kernel messages about I/O:
echo 1 > /proc/sys/vm/block_dump
This makes the kernel start writing messages about every I/O operation that takes place. Now all you have to do is get those messages and feed them into my script:
while true; do sleep 1; dmesg -c; done | perl iodump
Wait a little while, then cancel the script. The results should look something like the following:
root@kanga:~# while true; do sleep 1; dmesg -c; done | perl iodump ^C# Caught SIGINT. TASK PID TOTAL READ WRITE DIRTY DEVICES firefox 4450 4538 251 4287 0 sda4, sda3 kjournald 2100 551 0 551 0 sda4 firefox 28452 185 185 0 0 sda4 kjournald 782 59 0 59 0 sda3 pdflush 31 30 0 30 0 sda4, sda3 syslogd 2485 2 0 2 0 sda3 firefox 28414 2 2 0 0 sda4, sda3 firefox 28413 1 1 0 0 sda4 firefox 28410 1 1 0 0 sda4 firefox 28307 1 1 0 0 sda4 firefox 28451 1 1 0 0 sda4
I deliberately generated a bunch of I/O by deleting my Firefox history and cache.
Do dmseq se zapisuje neco jako….
firefox(4450): WRITE block 25058328 on sda4 firefox(4450): WRITE block 25058336 on sda4 firefox(4450): WRITE block 25059104 on sda4
UseCase2 (process read/write)
A quick way is to look at the /proc/[PID]/io file.
Example:
$ cat /proc/1944/io read_bytes: 17961091072 write_bytes: 8192000 cancelled_write_bytes: 32768
read/write per process
#!/bin/bash
while [ 1 ]
do
#CPIDS=`pgrep cache`
CPIDS=`ls /proc/ | grep "[0-9]"`
i=0
for P in $CPIDS
do
STATA[i]=`cat /proc/$P/io 2>/dev/null | grep "^write_bytes:" | cut -d " " -f 2`
i=$((i+1))
done
sleep 1
i=0
for P in $CPIDS
do
STATB[i]=`cat /proc/$P/io 2>/dev/null | grep "^write_bytes:" | cut -d " " -f 2`
i=$((i+1))
done
i=0
for P in $CPIDS
do
[[ ${STATB[$i]} -gt 0 ]] && [[ ${STATA[$i]} -gt 0 ]] && DIFF=$(( ${STATB[$i]} - ${STATA[$i]} )) || DIFF=0
[[ $DIFF -gt 0 ]] && {
DIFF=$((DIFF/1024))
echo "PID $P: $DIFF kB/s (${STATB[$i]} - ${STATA[$i]})"
}
i=$((i+1))
done
echo "---"
done
UseCase3 (high IO waiting)
wa -- iowait (Amount of time the CPU has been waiting for I/O to complete)
- procesy ve stavu D
PROCESS STATE CODES
D uninterruptible sleep (usually IO)
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z defunct ("zombie") process, terminated but not reaped by its parent.
- vypis procesu ve stavu D
for x in `seq 1 1 10`; do ps -eo state,pid,cmd | grep "^D"; echo "----"; sleep 5; done
minitorovaniio.1409928201.txt.gz · Poslední úprava: (upraveno mimo DokuWiki)
