Linux command of the day, 4 of 31 - iostat
iostat
I’m looking briefly at a Linux command every day for a month. Today: iostat. This isn’t intended to be a tutorial, just some brief notes for fun
Yesterday I looked at stat
, and today it’s iostat
. They’re not super closely related AFACIT!
iostat
works by watching how much time a “device” spends being used versus the rate of data it’s transferring. So, it can show up things like “this disk drive is whizzing and whirring but not much data is actually moving” or “this device is running totally red line”!
iostat can tell you utilisation reports for 3 devices:
- CPU
- Device
- Network filesystem
On my macbook, I see:
$ iostat
disk0 disk2 cpu load average
KB/t tps MB/s KB/t tps MB/s us sy id 1m 5m 15m
8.31 60 0.48 3.61 0 0.00 6 4 90 2.14 3.04 3.18
As ever, the Mac version of iostat
isn’t precisely aligned with the Linux one so YMMV
I can ‘watch’ my disk with:
$ iostat -d -c 10
disk0 disk2
KB/t tps MB/s KB/t tps MB/s
8.31 60 0.48 3.61 0 0.00
5.20 87 0.44 0.00 0 0.00
8.00 2 0.02 0.00 0 0.00
52.04 93 4.72 0.00 0 0.00
5.02 703 3.45 0.00 0 0.00
5.60 5 0.03 0.00 0 0.00
0.00 0 0.00 0.00 0 0.00
35.67 60 2.08 0.00 0 0.00
4.82 831 3.91 0.00 0 0.00
5.60 70 0.38 0.00 0 0.00
These are:
- KB/t: kilobytes per transfer
- tps: transfers per second
- MB/s: megabytes per second
If I run dd if=/dev/random of=/tmp/largefile bs=1024 count=4000000
I see it spike up FAST:
disk0 disk2
KB/t tps MB/s KB/t tps MB/s
4.84 19 0.09 0.00 0 0.00
335.90 419 137.29 0.00 0 0.00 <-- started dd
573.90 243 136.34 0.00 0 0.00
632.09 234 144.36 0.00 0 0.00
462.51 314 141.71 0.00 0 0.00
657.03 225 144.25 0.00 0 0.00
471.74 296 136.38 0.00 0 0.00
577.26 241 135.80 0.00 0 0.00
229.82 614 137.91 0.00 0 0.00
314.77 445 136.66 0.00 0 0.00
225.40 626 137.77 0.00 0 0.00
223.94 639 139.64 0.00 0 0.00
715.38 194 135.72 0.00 0 0.00
220.40 442 95.06 0.00 0 0.00 <-- cancelled dd
7.58 19 0.14 0.00 0 0.00
So it’s really clear when a disk is getting hammered - provided you have a baseline to compare it to!
You can combine iostat
this with lsof
to figure out what is likely to be generating all the disk activity.