The iostat command is for getting the CPU and input-output devices' statistics for Linux and Unix systems. For example,
$ iostat Linux 3.0.0-14-generic (hostname) Wednesday 06 June 2012 _i686_ (2 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 17.38 0.13 3.13 1.63 0.00 77.74 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 11.78 111.65 69.79 11663838 7290650
The above output has two reports, the CPU utilization report and the device utilization report. The CPU utilization report, in this case, tells that the CPU was working 17.38% time at the user level, 0.13% time at the user level with nice priority, 3.13% time at the system level, 1.63% time waiting for I/O, 0% time waiting while the hypervisor was servicing another virtual processor and 77.74% time was plain idle. The CPU utilization report gives the average of data for all the CPUs in the system. The device utilization report gives data for the disk /dev/sda. In this case /dev/sda has been carrying out 11.78 transfers per second, doing 111.65 kilobytes of disk read and 69.79 kilobytes of disk writes in the process. Multiple I/O transfer requests may be merged into a single I/O request. A total of 11,663,838 kilobytes were read and 7,290,650 kilobytes were written to sda. All data is since the time of system boot.
The iostat command is a part of the sysstat package for performance monitoring under Linux.
Options
[interval [count]]
We can get the iostat output on a continuous basis by indicating an interval and, optionally, a count for number of reports. If no count is given, iostat keeps on giving the reports till it is interrupted with a Control-C or alternate means. The syntax is,
iostat [interval [count]]
The first report gives data since the time of system boot. After that, the subsequent reports give data since the immediate preceding report.
Device and partitions
Passing the device name as a parameter gives information about that device. If, instead of device name keyword ALL is passed, data about all devices that have been defined in the system, including the ones that have never been used, is printed.
$ iostat xvdap1 Linux 2.6.38-8-virtual (hostname) 06/07/2012 _i686_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.25 0.00 0.04 0.10 0.40 99.21 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn xvdap1 0.61 0.11 4.37 528073 21832060 $ iostat ALL Linux 2.6.38-8-virtual (hostname) 06/07/2012 _i686_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.25 0.00 0.04 0.10 0.40 99.21 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn ram0 0.00 0.00 0.00 0 0 ram1 0.00 0.00 0.00 0 0 ram2 0.00 0.00 0.00 0 0 ram3 0.00 0.00 0.00 0 0 ram4 0.00 0.00 0.00 0 0 ram5 0.00 0.00 0.00 0 0 ram6 0.00 0.00 0.00 0 0 ram7 0.00 0.00 0.00 0 0 ram8 0.00 0.00 0.00 0 0 ram9 0.00 0.00 0.00 0 0 ram10 0.00 0.00 0.00 0 0 ram11 0.00 0.00 0.00 0 0 ram12 0.00 0.00 0.00 0 0 ram13 0.00 0.00 0.00 0 0 ram14 0.00 0.00 0.00 0 0 ram15 0.00 0.00 0.00 0 0 loop0 0.00 0.00 0.00 0 0 loop1 0.00 0.00 0.00 0 0 loop2 0.00 0.00 0.00 0 0 loop3 0.00 0.00 0.00 0 0 loop4 0.00 0.00 0.00 0 0 loop5 0.00 0.00 0.00 0 0 loop6 0.00 0.00 0.00 0 0 loop7 0.00 0.00 0.00 0 0 xvdap1 0.61 0.11 4.37 528073 21832060 xvdap2 0.01 0.00 0.02 1355 113584 xvdap3 0.00 0.00 0.00 1076 4596
In the above report, xvdap1 is being used more than xvdap2, which could be an input for more balanced system configuration. The -z option tells iostat to skip the devices for which there was no activity during the reporting period. So the above example, with the -z option, gives a more compact report.
$ iostat -z ALL Linux 2.6.38-8-virtual (hostname) 06/07/2012 _i686_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.25 0.00 0.04 0.10 0.40 99.21 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn xvdap1 0.61 0.11 4.38 528073 21864032 xvdap2 0.01 0.00 0.02 1355 113720 xvdap3 0.00 0.00 0.00 1076 4596
The -p option gives the information for all the partitions of the concerned block device. Again, usage of keyword ALL results in the report for all partitions of all block devices.
$ iostat -p sda Linux 3.0.0-14-generic (hostname) Thursday 07 June 2012 _i686_ (2 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 16.62 0.14 2.74 1.20 0.00 79.30 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 8.70 80.75 59.65 15299966 11302046 sda1 0.00 0.00 0.00 672 0 sda2 4.66 16.59 16.51 3142998 3127448 sda3 2.57 51.14 5.77 9689574 1094096 sda4 0.00 0.00 0.00 6 0 sda5 1.44 12.68 37.36 2402360 7077601 sda6 0.01 0.33 0.02 63035 2901 sda7 0.00 0.00 0.00 640 0
Extended statistics
The -x option gives the extended statistics. For example,
$ iostat -z -x -p ALL Linux 3.0.0-14-generic (hostname) Thursday 07 June 2012 _i686_ (2 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 16.50 0.14 2.73 1.18 0.00 79.45 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 1.93 4.02 6.58 1.98 79.41 59.03 32.32 0.16 18.80 13.42 36.62 2.73 2.34 sda1 0.00 0.00 0.00 0.00 0.00 0.00 8.00 0.00 7.19 7.19 0.00 7.19 0.00 sda2 0.45 3.11 3.64 0.95 16.32 16.23 14.19 0.08 16.70 9.85 42.90 2.09 0.96 sda3 0.43 0.19 2.32 0.21 50.29 5.70 44.27 0.05 21.00 19.59 37.00 4.73 1.20 sda4 0.00 0.00 0.00 0.00 0.00 0.00 6.00 0.00 212.00 212.00 0.00 212.00 0.00 sda5 1.04 0.72 0.61 0.81 12.47 37.08 69.58 0.03 21.52 11.24 29.26 5.50 0.78 sda6 0.02 0.00 0.01 0.00 0.33 0.02 78.45 0.00 16.81 14.76 52.66 8.72 0.01 sda7 0.00 0.00 0.00 0.00 0.00 0.00 8.00 0.00 6.03 6.03 0.00 6.03 0.00
The rrqm/s column gives read requests merged per second. Similarly, the wrqm/s column gives the write requests merged per second. r/s and w/s columns give read and write requests completed per second after merges. The next two columns, rkB/s and wkB/s give number of kilobytes read and written per second respectively. The avgrq-sz column gives the average size of requests in sectors issued to the device. The avgqu-sz column gives the queue length of the requests issued to the device. The await column gives the average time in milliseconds for the I/O requests to be serviced by this device. This includes the time spent in the queue. The r_await and w_await columns give average time in milliseconds for read and write requests to get serviced respectively. This, again, includes the time spent by the requests in the queue. The svctm column gives the average service time in milliseconds for actual servicing of I/O requests for this device. Comparing this time with the await time tells us that the time for servicing the I/O request is much smaller than the wait times. Finally, the %util column gives the percent of the CPU time during which the I/O requests were given to this device.
Miscellaneous Options
The -c option prints the CPU utilization report only, provided conflicting options like -x, -p and -d are not given. Similarly, -d option prints the device utilization report only and not the CPU utilization report. The -k option results in data printed in the units of kilobytes per seconds (the default), whereas with the -m option the data is printed in the units of megabytes per seconds.