The iostat command in Linux: input/output statistics

Introduction

In Linux system administration, understanding input/output (I/O) behavior is essential for detecting bottlenecks and optimizing performance. The iostat command, part of the sysstat package, provides a clear and real-time view of block device and CPU statistics.

What is iostat

iostat stands for Input/Output Statistics and is responsible for reporting metrics such as transfers per second, amount of data read and written, wait time, and device utilization. Its output helps administrators and developers understand whether storage is saturated or if the CPU is waiting for I/O operations.

Installation

In most modern distributions, iostat is not installed by default. To obtain it, simply install the sysstat package. On Debian/Ubuntu run:

  • sudo apt update
  • sudo apt install sysstat

On Red Hat/CentOS the command is:

  • sudo yum install sysstat

After installation, the sysstat service starts automatically and begins collecting data that iostat can display.

Basic Syntax

The simplest way to use iostat is to run it without arguments, which shows a summary since the last boot:

iostat

To obtain periodic samples, two parameters are added: the interval in seconds and the number of reports desired. For example, to see three updates every two seconds:

iostat 2 3

Most Used Options

iostat includes several flags that extend its analytical capability:

  • -c: show only CPU statistics.
  • -d: show only device statistics.
  • -k: display values in kilobytes instead of blocks.
  • -m: display values in megabytes.
  • -p NAME: show statistics for a specific partition and its underlying devices.
  • -t: include a timestamp on each output line.
  • -x: show extended statistics, such as await, svctm, and %util.

Interpretation of the Main Fields

When using the -x option, iostat displays columns that deserve attention:

  • tps: transfers per second (reads + writes).
  • kB_read/s: kilobytes read per second.
  • kB_wrtn/s: kilobytes written per second.
  • kB_dscd/s: kilobytes discarded (useful on SSD disks).
  • await: average time in milliseconds that an I/O request waits to be served (includes queue and service).
  • svctm: average service time of the request (excluding queue).
  • %util: percentage of time the device was busy serving requests. A value close to 100 % indicates saturation.

Practical Example: Monitoring a Disk in Real Time

Suppose we want to observe the /dev/sda device every second for ten seconds, with extended statistics and in megabytes:

iostat -xm /dev/sda 1 10

The output will show lines like:

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.10    12.34     5.67   120.5    45.2    28.5     0.12    8.45    7.20   10.10   1.20   23.4

In this case, a %util of 23 % indicates the disk has available capacity, while an await of around 8 ms shows acceptable latency.

Example: Combining Interval and Timestamp

To keep a historical record with useful timestamps in monitoring scripts, you can use:

iostat -xt 2 5 >> /var/log/iostat_log.txt

Each

This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .