CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / System Information / iostat

iostat

Measure disk throughput, latency and utilisation

Intermediateperformancediskmonitoring

iostat (from the sysstat package) reports CPU usage and per-device disk statistics: requests per second, throughput, average latency (await), queue size and %util. With -x it is the standard tool for answering 'is the disk the bottleneck, and which one?'.

Syntaxiostat [-c] [-d] [-x] [-s] [-z] [-y] [-h|-k|-m] [-p DEV] [DEVICE...] [INTERVAL [COUNT]]

Watch it run

You're investigating slow queries and want disk statistics, but iostat isn't on this minimal image.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
iostat

iostat ships in the sysstat package, together with sar, mpstat and pidstat. Minimal and container images often lack it.

Anatomy of a command

$
commandiostat

sysstat's iostat: reads /proc/diskstats and /proc/stat and prints rates per interval.

How it works

The kernel keeps per-device counters in /proc/diskstats: reads and writes completed, sectors transferred, merged requests, milliseconds spent on reads and writes, requests in flight, and milliseconds the device had at least one request in flight. iostat samples them every interval and divides the differences by the elapsed time. r/s and w/s are completed requests per second; rkB/s and wkB/s throughput; await (r_await, w_await) is the average time from submission to completion, including time queued in the kernel, in ms; aqu-sz is the average number of requests in flight; %util is the share of time the device was busy. %util is accurate for a single-queue disk, but SSDs and NVMe serve many requests in parallel, so they can show 100% while having headroom: latency (await) and queue size tell you more. The avg-cpu block, including %iowait, comes from /proc/stat.

Options you'll actually use

-xExtended stats: r/s, w/s, rkB/s, wkB/s, r_await, w_await, aqu-sz, %util
-sShort version of -x that fits 80 columns: tps, kB/s, await, %util
-d / -cOnly the device report / only the CPU report
-zOmit devices with no activity
-ySkip the since-boot first report
-h / -mHuman-readable units / MB instead of kB
-p DEVInclude partitions of DEV
-tPrint a timestamp with each report
-NShow LVM/device-mapper names instead of dm-0

Common mistakes

Running iostat with no interval during an incident

Without an interval you get one report averaged since boot, which smooths away the current problem.

iostat -dxz 1 5, and read from the second report on (or add -y)
Concluding an NVMe disk is maxed out because %util is 100

SSDs and NVMe process many requests in parallel; %util only says at least one request was in flight all the time.

Judge by await and aqu-sz against the device's normal latency
Blaming the disk for high %iowait alone

iowait is idle CPU time while some I/O is outstanding; it shrinks when other work keeps the CPUs busy, and varies with CPU count.

Check per-device await, aqu-sz and throughput with iostat -x

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Show extended device statistics every second, 3 times, hiding idle devices.

  2. 2

    Show just the CPU report, skipping the since-boot sample, 2 times at 2-second intervals.

  3. 3

    Generate disk writes with dd and watch the device in iostat at the same time.

Related commands

vmstatReport CPU, memory, swap and I/O activity over timepidstatPer-process CPU, memory, disk and context switches over timedfReport used and free space per filesystemlsblkList disks, partitions and where they are mountedsarCollect and replay system activity history
PreviousvmstatNexttar
Linux / System Information / iostat

iostat

Measure disk throughput, latency and utilisation

Intermediateperformancediskmonitoring

iostat (from the sysstat package) reports CPU usage and per-device disk statistics: requests per second, throughput, average latency (await), queue size and %util. With -x it is the standard tool for answering 'is the disk the bottleneck, and which one?'.

Syntaxiostat [-c] [-d] [-x] [-s] [-z] [-y] [-h|-k|-m] [-p DEV] [DEVICE...] [INTERVAL [COUNT]]

Watch it run

You're investigating slow queries and want disk statistics, but iostat isn't on this minimal image.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
iostat

iostat ships in the sysstat package, together with sar, mpstat and pidstat. Minimal and container images often lack it.

Anatomy of a command

$
commandiostat

sysstat's iostat: reads /proc/diskstats and /proc/stat and prints rates per interval.

How it works

The kernel keeps per-device counters in /proc/diskstats: reads and writes completed, sectors transferred, merged requests, milliseconds spent on reads and writes, requests in flight, and milliseconds the device had at least one request in flight. iostat samples them every interval and divides the differences by the elapsed time. r/s and w/s are completed requests per second; rkB/s and wkB/s throughput; await (r_await, w_await) is the average time from submission to completion, including time queued in the kernel, in ms; aqu-sz is the average number of requests in flight; %util is the share of time the device was busy. %util is accurate for a single-queue disk, but SSDs and NVMe serve many requests in parallel, so they can show 100% while having headroom: latency (await) and queue size tell you more. The avg-cpu block, including %iowait, comes from /proc/stat.

Options you'll actually use

-xExtended stats: r/s, w/s, rkB/s, wkB/s, r_await, w_await, aqu-sz, %util
-sShort version of -x that fits 80 columns: tps, kB/s, await, %util
-d / -cOnly the device report / only the CPU report
-zOmit devices with no activity
-ySkip the since-boot first report
-h / -mHuman-readable units / MB instead of kB
-p DEVInclude partitions of DEV
-tPrint a timestamp with each report
-NShow LVM/device-mapper names instead of dm-0

Common mistakes

Running iostat with no interval during an incident

Without an interval you get one report averaged since boot, which smooths away the current problem.

iostat -dxz 1 5, and read from the second report on (or add -y)
Concluding an NVMe disk is maxed out because %util is 100

SSDs and NVMe process many requests in parallel; %util only says at least one request was in flight all the time.

Judge by await and aqu-sz against the device's normal latency
Blaming the disk for high %iowait alone

iowait is idle CPU time while some I/O is outstanding; it shrinks when other work keeps the CPUs busy, and varies with CPU count.

Check per-device await, aqu-sz and throughput with iostat -x

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Show extended device statistics every second, 3 times, hiding idle devices.

  2. 2

    Show just the CPU report, skipping the since-boot sample, 2 times at 2-second intervals.

  3. 3

    Generate disk writes with dd and watch the device in iostat at the same time.

Related commands

vmstatReport CPU, memory, swap and I/O activity over timepidstatPer-process CPU, memory, disk and context switches over timedfReport used and free space per filesystemlsblkList disks, partitions and where they are mountedsarCollect and replay system activity history
PreviousvmstatNexttar