9 Linux iostat Command Examples for Performance Monitoring

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.

What does iostat command do?

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 [option] [interval] [count]
  • interval parameter specifies duration of time in seconds between each report
  • 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 boot, while each subsequent report covers the time period since the last report was generated.

# iostat 2 3
Linux 3.10.0-514.16.1.el7.x86_64 (centos-01) 	05/23/2017 	_x86_64_  (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.65    0.00    0.18    0.02    0.00   99.15

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               0.88         4.29         7.07     217829     358600

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.01    0.00    0.50    0.00    0.00   98.49

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               0.50         0.00         2.01          0          4

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           3.00    0.00    0.50    0.00    0.00   96.50

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               1.00         0.00        30.00          0         60

1. Get processor and device report

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 only the CPU report,

# iostat -c 1 2
Linux 3.10.0-514.16.1.el7.x86_64 (centos-01) 	05/23/2017   _x86_64_   (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.65    0.00    0.18    0.02    0.00   99.14

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00    0.00    0.00    0.00  100.00

or the -d option to get only the device report.

# iostat -d 2 1
Linux 3.10.0-514.16.1.el7.x86_64 (centos-01) 	05/23/2017 	_x86_64_  (1 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               0.88         4.27         7.10     217829     362356

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

The device report shows transfers per second, number of blocks per second read and written, the total number of blocks read, and the total number of blocks written.

2. Show report easily readable

For more readable report you can you can use the -k or -m parameter to change the columns to be expressed in kilobytes or megabytes instead of blocks.

# iostat -d -m 2 2
Linux 3.10.0-514.16.1.el7.x86_64 (centos-01) 	05/23/2017 	_x86_64_	(1 CPU)

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
vda               0.88         0.00         0.01        212        373

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
vda               0.51         0.00         0.00          0          0

3. Extend report

You can display extended disk I/O statistics with -x option

$ iostat -x
Linux 3.10.0-514.16.1.el7.x86_64 (centos7-srv) 	05/23/2017 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4.73    0.63    2.70    2.44    0.00   89.51

Device:rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda    0.00     0.41    8.81    2.61   282.22   100.51    67.03     0.18   15.77   15.42   16.96   4.44   5.07
sdb    0.00     0.00    0.12    0.00     0.77     0.00    12.23     0.00    3.42    3.06  104.00   3.21   0.04
sdf    0.00     0.00    0.28    0.00     2.10     0.00    14.95     0.00    0.31    0.31    0.00   0.30   0.01
sdg    0.00     0.00    0.08    0.00     0.50     0.00    13.13     0.00    0.36    0.36    0.00   0.35   0.00
sdh    0.00     0.00    0.08    0.00     0.50     0.00    13.13     0.00    0.39    0.39    0.00   0.38   0.00
sdi    0.00     0.00    0.08    0.00     0.50     0.00    13.13     0.00    0.13    0.13    0.00   0.11   0.00
sdj    0.00     0.00    0.08    0.00     0.50     0.00    13.13     0.00    0.04    0.04    0.00   0.04   0.00
dm-0   0.00     0.00    7.61    2.06   267.86    86.20    73.20     0.18   19.00   17.21   25.62   5.17   5.00

You can see that it lists some more information. You can have the extended detail for a partitular device as below

$ iostat -x sdf
Linux 3.10.0-514.16.1.el7.x86_64 (centos7-srv) 	05/23/2017 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4.19    2.46    2.50    2.91    0.00   87.93

Device:  rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sdf       0.00     0.00    0.23    0.00     1.70     0.00    14.95     0.00    0.31    0.31    0.00   0.30   0.01

4. Show statistic for a block device

You can get the report for each device (detail with each partition) connected to your server with -p parameter.

$ iostat -p 1 5
Linux 3.10.0-514.16.1.el7.x86_64 (centos7-srv) 	05/23/2017 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          10.99    0.36    6.21    7.11    0.00   75.33

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              32.73       822.62       221.28     624070     167872
sda1              5.79        38.20        41.74      28979      31666
sda2             26.81       783.36       179.54     594290     136206
sdb               0.37         2.23         0.00       1693          0
sdg               0.22         1.47         0.00       1116          0
sdh               0.22         1.47         0.00       1116          0
sdi               0.22         1.47         0.00       1116          0
sdj               0.22         1.47         0.00       1116          0
dm-0             27.59       780.73       179.54     592294     136206

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           8.08    0.00    1.01    0.00    0.00   90.91

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               0.00         0.00         0.00          0          0
sda1              0.00         0.00         0.00          0          0
sda2              0.00         0.00         0.00          0          0

The output has been truncated. You will have the report 5 times

5. Show statistic for a particular device

You can have multiple devices installed as the example above. Now, if you want to measure the statistics about a particular device, you must precise the device name

$ iostat -p sdf 1 2
Linux 3.10.0-514.16.1.el7.x86_64 (centos7-srv) 	05/23/2017 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           7.18    0.41    3.94    4.10    0.00   84.37

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sdf               0.47         3.54         0.00       4656          0
sdf1              0.09         0.70         0.00        920          0
sdf2              0.09         0.69         0.00        904          0
sdf3              0.09         0.69         0.00        904          0
sdf4              0.09         0.69         0.00        904          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           6.00    1.00    2.00    0.00    0.00   91.00

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sdf               0.00         0.00         0.00          0          0
sdf1              0.00         0.00         0.00          0          0
sdf2              0.00         0.00         0.00          0          0
sdf3              0.00         0.00         0.00          0          0
sdf4              0.00         0.00         0.00          0          0

You can see that it lists only the partitions of the selected disk

6. Show report for lvm2

You have seen that the -p option shows statistic for each device but it doesn't display lvm report. Now the -N option display the registered device mapper names for any device mapper devices which is useful to view lvm2 statistic

$ iostat -N
Linux 3.10.0-514.16.1.el7.x86_64 (centos7-srv) 	05/23/2017 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           9.02    0.36    4.98    5.47    0.00   80.18

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              25.28       632.63       174.38     624174     172044
sdb               0.28         1.72         0.00       1693          0
sdc               0.15         0.80         0.00        788          0
sdd               0.31         2.17         0.00       2144          2
sde               0.22         1.42         0.00       1405          2
sdf               0.63         4.72         0.00       4656          0
sdg               0.17         1.13         0.00       1116          0
sdh               0.17         1.13         0.00       1116          0
sdi               0.17         1.13         0.00       1116          0
sdj               0.17         1.13         0.00       1116          0
centos-root      21.35       600.43       142.28     592398     140378
centos-swap       0.19         1.54         0.00       1520          0
vg--01-lv_linear     0.06         0.46         0.00        456          0
vg--01-lv_stripe     0.06         0.46         0.00        456          0
vg--01-lv_mirror_rmeta_0     0.00         0.00         0.00          1          0
datavg-mirrorlv_rmeta_0     0.00         0.00         0.00          2          1
vg--01-lv_mirror_rimage_0     0.06         0.45         0.00        444          0
datavg-mirrorlv_rimage_0     0.06         0.45         0.00        444          0
vg--01-lv_mirror_rmeta_1     0.00         0.00         0.00          0          0
datavg-mirrorlv_rmeta_1     0.00         0.00         0.00          0          1
vg--01-lv_mirror_rimage_1     0.00         0.01         0.00         12          0
datavg-mirrorlv_rimage_1     0.00         0.01         0.00         12          0
vg--01-lv_mirror     0.06         0.46         0.00        456          0
datavg-mirrorlv     0.06         0.46         0.00        456          0
datavg-mirrorlv1_rmeta_0     0.00         0.00         0.00          1          0
datavg-mirrorlv1_rimage_0     0.03         0.32         0.00        316          0
datavg-mirrorlv1_rmeta_1     0.00         0.00         0.00          0          0
datavg-mirrorlv1_rimage_1     0.00         0.01         0.00         12          0
datavg-mirrorlv1     0.03         0.33         0.00        328          0

7. Display report only for device in activity

We can tell iostat to omit output for any devices for which there was no activity during the sample period with -z option.

$ iostat -z 
Linux 3.10.0-514.16.1.el7.x86_64 (centos7-srv) 	05/23/2017 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.38    0.57    1.08    0.72    0.00   95.25

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               2.90        90.19        56.16    1075726     669838
sdb               0.02         0.14         0.00       1693          0
sde               0.02         0.12         0.00       1405          2
sdg               0.01         0.09         0.00       1116          0
sdh               0.01         0.09         0.00       1116          0
sdj               0.01         0.09         0.00       1116          0
dm-0              2.59        87.53        53.50    1043950     638116
dm-1              0.02         0.13         0.00       1520         44
dm-4              0.00         0.00         0.00          1          0

Now we have a compact report

8. Get certain column of the report

The command show some information but you can need to keep only certain. You can filter the output.

To fetch for eample kB_read/s and kB_wrtn/s for lvm report do

$ iostat -N 10 2 | grep -w vg | awk {'print $3, $4'}
0.04 0.00
0.04 0.00
0.00 0.00
0.04 0.00
0.00 0.00
0.00 0.00
0.04 0.00
0.00 0.00
0.00 0.00
0.00 0.00
0.00 0.00
0.00 0.00
0.00 0.00
0.00 0.00

Were you see grep -w vg, the vg is because my volume group's name begin by vg, it is vg-01. So the result listed is for my volume group.

If you want the average time for read and write request issued to the device to be served, do as below

$ iostat -x 15 | awk '/sda/ { print $11, $12}'
33.47 72.58
13.60 70.10
10.00 7.25
9.11 84.71
13.95 24.27
14.46 51.38
14.00 31.33
14.80 40.90

9. Save report into a file

The command show the report on the standard output, it means that you will need to launch the command every time to check the result. You can save the result into a file to consult it every time you need to check the last values:

iostat -x 3 6 | awk '/sda/ { print $11, $12}' > outfile

Now we can check the file

$ cat outfile 
33.10 70.90
3.56 63.50
5.12 8.00
3.19 42.00
12.58 43.63
0.00 16.80

Conclusion

iostat command provides cpu and input/output for the devices and partitions. There are some options which can be used to manipulate the report and you can see it check every time data saved. It is a good tool use by some monitoring tools.

Filed Under : LINUX HOWTO, MONITORING

Tagged With : ,

Free Linux Ebook to Download

Leave a Reply

All comments are subject to moderation.