iostat Command

The iostat command is a powerful utility in Linux that monitors and reports CPU utilization and I/O statistics for devices and partitions. It is part of the sysstat package and is essential for system administrators and developers to diagnose performance bottlenecks related to disk I/O and CPU usage.

Syntax

iostat [ OPTIONS ] [ <interval> [ <count> ] ]

Description

iostat provides a snapshot of system activity, including average CPU load, and detailed statistics for each storage device. It can display persistent device statistics since the last boot or provide continuous updates at specified intervals, making it suitable for real-time monitoring.

Key metrics reported by iostat:

  • CPU Utilization: Percentage of time spent in user mode, system mode, idle, waiting for I/O, etc.
  • Device Utilization: Reads/writes per second, data transferred (KB/s, MB/s), average queue length, average request size, and device utilization percentage.
  • Extended Statistics: More detailed metrics like average service time (await), average queue length (avgqu-sz), and average request size (avgrq-sz).

Common Options

Option Description
-c Display CPU utilization report.
-d Display device utilization report.
-h Make the output human-readable.
-k Display statistics in kilobytes per second.
-m Display statistics in megabytes per second.
-x Display extended statistics.
-p [ { device [,...] | ALL } ] Display statistics for block devices and their partitions.
<interval> Time in seconds between each report.
<count> Number of reports to display.

Examples

Basic CPU and device I/O report

iostat

Displays a single report of CPU and device I/O statistics since the last boot.

Continuous monitoring every 2 seconds

iostat 2

Displays a new report every 2 seconds continuously.

Display 5 reports every 3 seconds

iostat 3 5

Displays 5 reports of CPU and device I/O statistics, with a 3-second interval between each.

Show extended device statistics in human-readable format

iostat -x -h

Provides detailed I/O statistics for devices, with sizes in human-readable units (e.g., MB/s).

Monitor specific devices

iostat -d /dev/sda /dev/sdb 5

Monitors I/O statistics for /dev/sda and /dev/sdb every 5 seconds.

Display CPU and disk statistics in megabytes

iostat -c -d -m

Shows CPU utilization and device I/O in megabytes per second.

See also