Krzysztof Bober
Krzysztof Bober

Reputation: 71

Script for monitoring disk i/o rates on Linux

I need a for monitoring ALL disk i/o rates on Linux using bash, awk, sed. The problem is that it must return one row per time interval (so this one row should contain: tps, kB_read/s, kB_wrtn/s, kB_read, kB_wrtn, but summarized per all disks). Natural choice here is of course:

 -d -k -p $interval $loops

To limit it to all disks I use:

 -d -k -p `parted -l | grep Disk | cut -f1 -d: | cut -f2 -d' '` 

Now the nice trick to summarize columns:

  -d -k -p `parted -l | grep Disk | cut -f1 -d: | cut -f2 -d' '` > /tmp/jPtafDiskIO.txt     
echo `date +"%H:%M:%S"`,`awk 'FNR>2' /tmp/jPtafDiskIO.txt | awk 'BEGIN {FS=OFS=" "}NR == 1 { n1 = $2; n2 = $3; n3 = $4; n4 = $5; n5 = $6; next }    { n1 += $2; n2 += $3; n3 += $4; n4 += $5; n5 += $6 }    END { print n1","n2","n3","n4","n5 }'` >> diskIO.log     

I am almost there, however this (running in the loop) makes being invoked each time from beginning, so I don't get the statistics from interval to interval, but always averages (so each invoke brings me pretty the same output).

I know it sounds complicated, but maybe somebody has an idea? Maybe totally different approach? Thx.

EDIT:

Sample input (/tmp/jPtafDiskIO.txt):

> Linux 2.6.18-194.el5 (hostname)  08/25/2012
> 
> Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
> sda               0.00         0.00         0.00      35655         59
> sda2              0.00         0.00         0.00         67        272
> sda1              0.00         0.00         0.00        521        274
> sdb              52.53         0.56       569.40   20894989
> 21065384388 sdc               1.90        64.64        10.93
> 2391333384  404432217 sdd               0.00         0.00         0.04
> 17880    1343028

Output diskIO.log:

16:53:12,54.43,65.2,580.37,2412282496,21471160238

Upvotes: 1

Views: 4502

Answers (2)

dstromberg
dstromberg

Reputation: 7187

dstat might be what you're looking for. It has a lot of things it can report on, with some common ones displayed by default.

Upvotes: 2

Stephane Rouberol
Stephane Rouberol

Reputation: 4384

Why not use iotop http://guichaz.free.fr/iotop/ ?

Upvotes: 2

Related Questions