Even though iostat can show cumulative statistics on CPU utilisation …
root:/tmp> iostat -c 5 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
avgcpu: %user %nice %system %iowait %steal %idle
. 7.42 1.00 2.43 1.52 0.00 87.63
.
avgcpu: %user %nice %system %iowait %steal %idle
. 2.93 0.00 0.53 1.75 0.00 94.79
… its main use is to extract I/O stats …
root:/tmp> iostat 5 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
avgcpu: %user %nice %system %iowait %steal %idle
. 7.41 1.00 2.43 1.52 0.00 87.65
.
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 5.95 7.08 93.52 4747376 62743664
sdb 5.64 2.85 100.03 1914758 67112760
md127 5.75 6.80 91.48 4564249 61373872
dm0 0.08 1.61 0.41 1076852 275872
dm1 0.13 1.84 1.49 1236701 1002040
dm2 0.00 0.07 0.01 48153 6368
dm3 0.00 0.02 0.01 11721 4644
.
avgcpu: %user %nice %system %iowait %steal %idle
. 3.28 0.00 1.18 3.71 0.00 91.83
.
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 152.60 0.00 2648.60 0 13243
sdb 156.00 0.00 3450.20 0 17251
md127 156.20 0.00 2648.00 0 13240
dm0 0.00 0.00 0.00 0 0
dm1 0.00 0.00 0.00 0 0
dm2 0.00 0.00 0.00 0 0
dm3 0.00 0.00 0.00 0 0
When iostat is executed without any options, the default flags -c and -d are used. So “iostat -d 5 2” would show the same output as the example above minus the average CPU part.
Usually iostat is used to monitor I/O workload on disk devices and is run a number of times a few seconds apart. But we can also run it without specifying any iterations/wait_intervals:
root:/tmp> iostat
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
avgcpu: %user %nice %system %iowait %steal %idle
. 7.41 1.00 2.43 1.52 0.00 87.65
.
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 6.02 7.09 94.79 4763116 63636715
sdb 5.72 2.86 101.35 1919430 68046611
md127 5.82 6.81 92.74 4575261 62261928
dm0 0.08 1.60 0.41 1076852 275912
dm1 0.13 1.86 1.51 1246101 1011140
dm2 0.00 0.07 0.01 48153 6368
dm3 0.00 0.02 0.01 11721 4644
The example above shows the average tps (transfers or I/Os per second), Kbytes_read/sec and
Kbytes_written/sec, total Kbytes read and total Kbytes written since boot. So most of the time they are a bit less than useless stats.
We will normally run iostat specifying a waiting interval and a number of iterations:
root:/tmp> iostat -d 5 → will extract the stats every 5 seconds forever
root:/tmp> iostat -d 5 1000 → will extract the stats 1000 times and exit
The most useful iostat options are:
-
-m → shows Mbytes rather than the default Kbytes
-t → shows the current timestamp at every iteration
-x → shows extended statistics (queue size & length, avg wait time, etc)-
-N → shows mapped device names
-y → omits the 1 st iteration showing stats since boot
-z → omits those devices without any I/O activity
-p <dev|ALL> → show stats for device and its partitions (default is just device)
-j ID|LABEL|UUID → show the device by ID/LABEL/UUID rather than its device name
-g group <dev1,dev2,… ALL> → gathers cumulative stats for all the devices in group
-T → shows stats of group defined with -g flag and omits individual devices
Let’s see some examples and how the output changes with the different flags. Without any flags we get both CPU and disk I/O stats:
root:/tmp> iostat 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
avgcpu: %user %nice %system %iowait %steal %idle
. 3.38 0.00 0.38 3.13 0.00 93.12
.
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 145.00 0.00 2198.25 0 4396
sdb 141.00 0.00 2182.25 0 4364
md127 141.50 0.00 2182.00 0 4364
dm0 0.00 0.00 0.00 0 0
dm1 0.00 0.00 0.00 0 0
dm2 0.00 0.00 0.00 0 0
dm3 0.00 0.00 0.00 0 0
With the -c flag we get CPU stats:
root:/tmp> iostat -c 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
avgcpu: %user %nice %system %iowait %steal %idle
. 3.38 0.00 0.38 3.13 0.00 93.12
With the -d flag we get disk I/O stats:
root:/tmp> iostat -d 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 109.00 0.00 2038.75 0 4077
sdb 108.50 0.00 2036.75 0 4073
md127 108.50 0.00 2038.00 0 4076
dm0 0.00 0.00 0.00 0 0
With -y the first set of “since-boot” figures is ommitted. The -m flag shows data in mbytes:
root:/tmp> iostat -dym 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 143.00 0.00 2.17 0 4
sdb 143.00 0.00 2.17 0 4
md127 142.00 0.00 2.17 0 4
dm0 0.00 0.00 0.00 0 0
With -t (timestamp) and -x (extended stats) we get …
root:/tmp> iostat -dymxt 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
10/23/2015 11:06:58 AM
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrqsz avgqusz await r_await w_await svctm %util
sda 0.00 0.00 0.00 97.50 0.00 1.94 40.78 0.67 6.85 0.00 6.85 2.06 20.10
sdb 0.00 0.50 0.00 98.00 0.00 1.95 40.69 3.85 39.24 0.00 39.24 7.56 74.05
md127 0.00 0.00 0.00 93.50 0.00 1.94 42.48 0.00 0.00 0.00 0.00 0.00 0.00
dm0 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
dm1 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
dm2 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
dm3 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
With -N (mapped device name) we get …
root:/tmp> iostat -dymxtN 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
10/23/2015 11:06:58 AM
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrqsz avgqusz await r_await w_await svctm %util
sda 0.00 0.00 0.00 97.50 0.00 1.94 40.78 0.67 6.85 0.00 6.85 2.06 20.10
sdb 0.00 0.50 0.00 98.00 0.00 1.95 40.69 3.85 39.24 0.00 39.24 7.56 74.05
md127 0.00 0.00 0.00 93.50 0.00 1.94 42.48 0.00 0.00 0.00 0.00 0.00 0.00
vg-root 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
vgdata-docs 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
vgdata-music 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
vgdata-other 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
If we want the same as above but specifying just to devices to show stats for …
root:/tmp> iostat -dymxtN sda sdb 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
10/23/2015 11:06:58 AM
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrqsz avgqusz await r_await w_await svctm %util
sda 0.00 0.00 0.00 97.50 0.00 1.94 40.78 0.67 6.85 0.00 6.85 2.06 20.10
sdb 0.00 0.50 0.00 98.00 0.00 1.95 40.69 3.85 39.24 0.00 39.24 7.56 74.05
If we want the same as above but showing stats for the 2 devices and its partitions, then we use -p:
root:/tmp> iostat -dymxtN -p sda -p sdb 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
10/23/2015 11:17:52 AM
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrqsz avgqusz await r_await w_await svctm %util
sda 0.00 0.00 0.00 1.00 0.00 0.00 1.00 0.01 14.50 0.00 14.50 14.50 1.45
sda1 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
sda2 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
sda3 0.00 0.00 0.00 1.00 0.00 0.00 1.00 0.01 14.50 0.00 14.50 14.50 1.45
sda4 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
sdb 0.00 0.00 0.00 1.00 0.00 0.00 1.00 0.07 71.00 0.00 71.00 71.00 7.10
sdb1 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
sdb2 0.00 0.00 0.00 1.00 0.00 0.00 1.00 0.07 71.00 0.00 71.00 71.00 7.10
sdb3 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
If we want the same as above but ommitting idle devices, then we use -z:
root:/tmp> iostat -dymxtNz -p sda -p sdb 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
10/23/2015 11:21:47 AM
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrqsz avgqusz await r_await w_await svctm %util
sda 0.00 0.00 0.00 1.00 0.00 0.00 1.00 0.01 14.50 0.00 14.50 14.50 1.45
sda3 0.00 0.00 0.00 1.00 0.00 0.00 1.00 0.01 14.50 0.00 14.50 14.50 1.45
sdb 0.00 0.00 0.00 1.00 0.00 0.00 1.00 0.07 71.00 0.00 71.00 71.00 7.10
sdb2 0.00 0.00 0.00 1.00 0.00 0.00 1.00 0.07 71.00 0.00 71.00 71.00 7.10
We can also show the devices by their ID with -j id:
root:/tmp> iostat -dym -j id 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
ata-HGST_HTS541010A9E680_J84000CHG28WSP
134.50 0.00 2.14 0 4
ata-TOSHIBA_MQ01ABD100_738RT2NYT
135.00 0.00 2.14 0 4
lvm-pv-uuid-06whsq-Y6uc-5rtl-0NrM-NN7D-HosS-JleYFN
135.00 0.00 2.14 0 4
dm-name-vg-root
0.00 0.00 0.00 0 0
dm-name-vg-data-docs
0.00 0.00 0.00 0 0
dm-name-vg-data-music
0.00 0.00 0.00 0 0
dm-name-vg-data-other
0.00 0.00 0.00 0 0
Let’s show now the devices by their label with -j label:
root:/tmp> iostat -dym -j label 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda
. 136.50 0.00 2.14 0 4
sdb
. 143.50 0.00 2.17 0 4
md127
. 136.50 0.00 2.14 0 4
LVROOT
. 0.00 0.00 0.00 0 0
DOCS
. 0.00 0.00 0.00 0 0
And now by their UUID with -j uuid:
root:/tmp> iostat -dym -j uuid 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda
. 136.50 0.00 2.14 0 4
sdb
. 143.50 0.00 2.17 0 4
md127
. 136.50 0.00 2.14 0 4
85ec848a-c542-4a3a-96ac-f2810edf310b
. 0.00 0.00 0.00 0 0
5564dc31-bf86-4d5a-a3fd-53bf5a7d13f1
. 0.00 0.00 0.00 0 0
Finally, let’s group together a few devices with -g groupname and show just those group stats:
root:/tmp> iostat -dym -g dmgroup1 dm-0 dm-1 dm-2 dm-3 -g dmgroup2 dm-4 dm-5 dm-6 -T 2
Linux 4.1.8100.fc21.x86_64 (envy17) 10/23/2015 _x86_64_ (8 CPU)
.
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
dmgroup1 0.00 0.00 0.00 0 0
dmgroup2 0.00 0.00 0.00 0 0
Most of the statistics shown by iostat are self-explanatory, but just in case let’s review what all the output fields are: