Iostat Linux Command - Performance Monitoring In Linux With Examples

May 10, 2011 | By
| Reply More

The iostat command in Linux is used to monitor the system's  I/O device loading, by observing the time devices are active in relation to their average transfer rates. The iostat command generates reports that can be used to modify your system's configuration to better balance the I/O load between physical disks, or to let you know when you have reached the threshold of your current disk subsystem.

When the command is run without arguments, it generates a detailed report containing information since the system was booted. You can provide two optional parameters to change this:

# iostat [interval [count] ]

The interval parameter specifies duration of time in seconds between each report while the
Count parameter allows you to specify the number of reports that are generated before iostat exits.

When the command is run for the first time with these arguments, the first report contains information since the system was booted, while each subsequent report covers the time period since the last report was generated.

The iostat command generates two reports by default, one for CPU utilization and another for device utilization. You can use either the –c option to get the CPU report, or the –d option to get just the device report.

# iostat
avg-cpu: %user %nice %sys %iowait %idle
4.92 0.00 0.78 0.77 93.53

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 1.22 0.19 33.09 690042 121113184
sda1 0.82 0.04 23.16 146122 84755712
sda2 0.40 0.15 9.93 543450 36357472
sdb 1.25 0.27 33.09 986982 121113184
sdb1 0.84 0.04 23.16 160592 84755712
sdb2 0.41 0.23 9.93 825960 36357472

In the output above, you can see that the first three columns of the CPU report show the percentage of CPU usage sequentially at the user level with a nice priority, and at the system level. The last two columns show the percentage of time the CPU was idle.

The device report shows transfers per second, number of blocks per second read and written, total number of blocks read, and total number of blocks written.
For more readable report you can you can use the –k parameter to change the last four columns to be expressed in kilobytes instead of blocks.

Display Version of iostat.

# iostat –v

View only CPU report.

# iostat –c
avg-cpu: %user %nice %sys %iowait %idle
4.92 0.00 0.78 0.77 93.53

Display only device report.

# iostat –d
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 1.22 0.19 33.09 690042 121113184
sda1 0.82 0.04 23.16 146122 84755712
sda2 0.40 0.15 9.93 543450 36357472
sdb 1.25 0.27 33.09 986982 121113184
sdb1 0.84 0.04 23.16 160592 84755712
sdb2 0.41 0.23 9.93 825960 36357472

Execute iostat command at interval of every 10 seconds for 3 times.

# iostat 10 3

avg-cpu: %user %nice %system %iowait %steal %idle
24.24 1.51 7.49 4.97 0.00 61.79

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 14.06 249.94 121.22 1337998 648912
sr0 0.01 0.23 0.00 1248 0

avg-cpu: %user %nice %system %iowait %steal %idle
13.13 0.00 6.21 0.60 0.00 80.06

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 2.51 4.01 28.86 40 288
sr0 0.00 0.00 0.00 0 0

avg-cpu: %user %nice %system %iowait %steal %idle
11.11 0.00 5.71 0.00 0.00 83.18

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.30 0.00 3.20 0 32
sr0 0.00 0.00 0.00 0 0

View statistics of specific devices

On a system you can have multiple devices installed. Now, if you want to measure the statistics about a particular device then you can use iostat command with –p option.

# iostat –p sda

avg-cpu: %user %nice %system %iowait %steal %idle
23.71 0.91 8.63 3.20 0.00 63.55

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 9.72 154.75 90.78 1375518 806888
sda1 0.00 0.11 0.00 946 0
sda2 0.00 0.00 0.00 14 0
sda3 4.74 115.66 30.38 1028073 270024
sda4 0.01 0.17 0.00 1522 0
sda5 4.96 38.75 60.40 344427 536864

To display device and NFS statistics with iostat:

# iostat –n

avg-cpu: %user %nice %sys %iowait %idle
4.33 0.01 1.16 0.31 94.19

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 2.83 0.35 5.39 29817402 457360056
sda1 3.32 50.18 4.57 4259963994 387641400
sda2 0.20 0.76 0.82 64685128 69718576
sdb 6.59 15.53 42.98 1318931178 3649084113
sdb1 11.80 15.53 42.98 1318713382 3649012985

Device: rBlk_nor/s wBlk_nor/s rBlk_dir/s wBlk_dir/s rBlk_svr/s wBlk_svr/s
192.168.1.4:/home/data 90.67 0.00 0.00 0.00 5.33 0.00
192.168.1.4:/backup 8.74 0.00 0.00 0.00 8.74 0.00
192.168.1.8:/media 0.02 0.00 0.00 0.00 0.01 0 00

To display extended disk I/O statistics with –x option:

# iostat –x

avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 27.86 63.53 61.77 132.91 1096.46 1598.40 13.84 0.21 1.06 2.28 44.45
sda1 0.69 33.22 48.54 129.63 773.30 1328.84 11.80 1.39 7.82 2.28 40.57
sda2 27.16 30.32 13.23 3.28 323.13 269.56 35.90 0.55 32.96 3.44 5.68
sdb 39.15 215.16 202.20 169.04 945.80 1073.13 5.44 1.05 2.78 1.64 60.91

sdb1 39.15 215.16 202.20 169.04 945.77 1073.13 5.44 1.05 2.78 1.64 60.91
sdc 8.90 3.63 356.56 51.40 207.01 972.24 2.89 1.04 2.56 1.55 63.30
sdc1 8.90 3.63 356.55 51.40 206.99 972.24 2.89 1.04 2.56 1.55 63.30

To display extended information for a specific partition (for example, /dev/sda1), do the following:

$ iostat -x sda1

avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s vgrq-sz avgqu-sz await svctm %util
sda1 0.69 33.21 48.54 129.62 773.23 1328.76 11.80 1.39 7.82 2.28 40.56

where options are explained below :

rrqm/s : - The number of read requests merged per second that were queued to the hard disk

wrqm/s :- The number of write requests merged per second that were queued to the hard disk

r/s :- The number of read requests per second

w/s : The number of write requests per second

rsec/s : The number of sectors read from the hard disk per second

wsec/s : The number of sectors written to the hard disk per second

avgrq-sz : The average size (in sectors) of the requests that were issued to the device.

avgqu-sz : The average queue length of the requests that were issued to the device

await : The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue as well as the time spent servicing them.

svctm : The average service time (in milliseconds) for I/O requests that were issued to the device

%util : Percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs when this value is close to 100%.

Filed Under : LINUX HOWTO, MONITORING

Tagged With :

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.