Linux Command - iostat
The Linux iostat command is used to display CPU and IO stats.
“On multiprocessor systems, CPU statistics are calculated system-wide as averages among all processors.”
The iostat command is part of the sysstat package. If iostat isn’t available on your system you may need to install sysstat first:
sudo apt install sysstat # Debian/Ubuntu/Mint
sudo yum install sysstat # RHEL/Fedora
sudo zypper install sysstat # OpenSUSE
sudo pacman -S sysstat # Arch Linux
sudo emerge -a app-admin/sysstat # Gentoo
Basic command format:
iostat interval count
| interval | time in seconds between reports |
| count | number of times to repeat report |
Report every 3 seconds continously:
iostat 3
Report every 2 seconds for 8 times:
iostat 2 8
JSON output:
iostat -o JSON 1 4
Options
Report:
| -c | CPU utilization report. |
| -d | Device utilization report. |
More:
| -x | Display extended statistics. |
| -s | Display a short (narrow) version of the report ( 80 char ) |
| -y | Omit first report with stats since boot, if multple reports |
| -z | omit output for devs with no activity |
Output:
| -o JSON | json output |
| –pretty | more human readable ( devs on right and sub reports) |
| –compact | don’t break into sub reports ( useful with –pretty ) |
| –human | human readable sizes |
| -h | combines –human and –pretty |
Partitions:
| -p | display for partitions |
| -p ALL | display for all partitions, even non used |
| -p sda | display for partitions, for this device |
More:
| -j ID,LABEL,PATH,UUID,… device […],ALL ] | use persistent names |
| -t | Print the time for each report displayed. |
Less useful/common options:
| -k | Display statistics in kilobytes per second. |
| -m | Display statistics in megabytes per second. |
| -N | Display the registered device mapper names for any device mapper devices. |
| -f directory | only use files from this dir |
| +f directory | use standard kernel files and and files in this dir |
| -g group_name { device […],ALL } | Display statistics for a group of devices. |
| -H | global stats for groups, use with -g option |
| –dec=xx | number of decimal places ( 2 is default ) |
| -V | Print version number then exit. |
Reports
This section just covers what each field means.
CPU Utilization Report
| %user | CPU utilization percentage at user level (application) |
| %nice | CPU utilization percentage at user level with nice priority. |
| %system | CPU utilization percentage atthe system level (kernel) |
| %iowait | percentage of time that the CPU or CPUs were idle during outstanding disk I/O request |
| %steal | percentage of time spent in involuntary wait while hypervisor servicing another virtual processor |
| %idle | percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. |
Device Utilization Report
Normal output fields:
Device: device (or partition) name as listed in the /dev directory. |tps | transfers ( I/O requests ) per second. Multiple logical requests per I/O request. A transfer is of indeterminate size.| |Blk_read/s (kB_read/s, MB_read/s) | blocks/kB/MB read per second| |Blk_wrtn/s (kB_wrtn/s, MB_wrtn/s) | blocks/kB/MB written per second| |Blk_dscd/s (kB_dscd/s, MB_dscd/s) | blocks/kB/MB data discarded per second| |Blk_read (kB_read, MB_read) | blocks/kB/MB data read| |Blk_wrtn (kB_wrtn, MB_wrtn) | blocks/kB/MB data written| |Blk_dscd (kB_dscd, MB_dscd) | blocks/kB/MB data discarded|
Short version output fields ( -s ):
| Blk_w+d/s (kB_w+d/s, MB_w+d/s) | blocks/kB/MB data written or discarded per second |
| Blk_w+d (kB_w+d, MB_w+d) | blocks/kB/MB data written or discarded |
Extended output fields ( -x ):
| r/s | read requests completed per second for the device. (after merges) |
| w/s | write requests completed per second for the device. (after merges) |
| d/s | discard requests completed per second for the device. (after merges) |
| f/s | flush requests completed per second for the device. (not tracked by partition, flush ops count as writes before merge) |
| rsec/s (rkB/s, rMB/s) | sectors (kilobytes, megabytes) read from the device per second. |
| wsec/s (wkB/s, wMB/s) | sectors (kilobytes, megabytes) written to the device per second. |
| dsec/s (dkB/s, dMB/s) | sectors (kilobytes, megabytes) discarded for the device per second. |
| rrqm/s | read requests merged per second that were queued to the device. |
| wrqm/s | write requests merged per second that were queued to the device. |
| drqm/s | discard requests merged per second that were queued to the device. |
| %rrqm | read requests merged together before being sent to the device. |
| %wrqm | write requests merged together before being sent to the device. |
| %drqm | discard requests merged together before being sent to the device. |
| rareq-sz | average size (in kilobytes) of the read requests |
| wareq-sz | average size (in kilobytes) of the write requests |
| dareq-sz | average size (in kilobytes) of the discard requests |
| r_await | average time (in milliseconds) for read requests |
| w_await | average time (in milliseconds) for write requests |
| d_await | average time (in milliseconds) for discard requests |
| f_await | average time (in milliseconds) for flush requests ( requests could be longer because they are batched). |
| aqu-sz | average queue length of the requests that were issued to the device. ( old version was avgqu-sz ) |
| %util | Percentage of elapsed time I/O requests were issued (bandwidth utilization, saturation occurs at 100% for devs serving requests serially) |
Not actually included in any output ( other variations of these are and this may change with different versions of the tool ):
| sec/s (kB/s, MB/s) | sectors (kilobytes, megabytes) read from, written to or discarded for the device per second. |
| rqm/s | I/O requests merged per second that were queued to the device. |
| areq-sz | average size (in kilobytes) of the I/O requests ( old version field was: avgrq-sz ) |
| await | average time (in milliseconds) for I/O requests |