The iostat command in Linux: input / output statistics

Introduction

In Linux system management, knowing the input and 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 and CPU device statistics.

What is iostat

iostat means Input / Output Statistics and is responsible for reporting metrics such as transfers per second, amount of data read and written, waiting time and use of the device. Your output helps managers and developers understand if the 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 get it, just install the sysstat package. Debian / Ubuntu runs:

  • sudo apt update
  • sudo apt install sysstat

In Red Hat / CentOS the command is:

  • sudo yum install sysstat

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

Basic syntax

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

iostat

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

iostat 2 3

Most commonly used options

iostat includes several flags that expand its analytical capacity:

  • -c: shows only CPU statistics.
  • -d: shows only device statistics.
  • -k: shows values in kilobytes instead of blocks.
  • -m: shows values in megabytes.
  • -p NAME: shows statistics of a specific partition and its underlying devices.
  • -t: includes a time mark on each output line.
  • -x: shows extended statistics, such as ahait, svctm and% util.

Interpretation of the main fields

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

  • tps: transfers per second (readings + scriptures).
  • kB _ read / s: kilobytes read per second.
  • kB _ wrtn / s: kilobytes written per second.
  • kB _ dscd / s: discounted kilobytes (useful on SSD disks).
  • wait: average time in milliseconds that an I / O application expects to be met (includes tail and service).
  • svctm: average service time of the application (not counting tail).
  • % util:% of time the device was occupied in response to requests. A value of about 100% indicates saturation.

Practical example: monitor a disk in real time

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

iostat -xm / dev / sda 1 10

The output will show lines such as:

Device: rrqm / s wrqm / s r / s w / s rkB / s wkB / s avgrq-sz avgqu-sz await r _ aait w _ aait svctm% utilsda 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, 23% util indicates that the disk has available capacity, while there is an acceptable latency of about 8 ms.

Example: combine interval and time mark

In order to keep a historical record with useful time marks in the scripts of the city, you can use:

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

Each report will include the date and time, which facilitates correlation with application events or other system records.

Use together with vmstat and sar

iostat is perfectly complemented by vmstat, which reports memory, processes and exchange activity, and with sar, which stores historical performance. A typical diagnostic flow could be:

  • Run vmstat 1 5 to see if there is high wait for I / O (wa field).
  • If wa is elevated, launch iostat -x 1 5 to identify which device is causing latency.
  • Use -d to review trends throughout the day and confirm whether the problem is timely or chronic.

Good practices and constraints

Some tips for reliable measurements:

  • Avoid running iostat in an environment with extreme CPU load, as the process itself consumes cycles.
  • Use sufficiently long intervals (at least 1 second) to capture representative averages.
  • Remember that iostat shows metrics at block level; it does not reveal details of file systems such as NFS latences or cache layers.
  • In virtualized systems, numbers can reflect the activity of the hyperviewer rather than the underlying physical disk.

Despite these caffeats, iostat remains an essential tool for any professional who needs to validate the storage performance in Linux.

Conclusion

The iostat command provides a clear window to the input and output statistics, allowing you to detect bottlenecks, plan capacity and optimize applications. Its simple syntax, combined with flexible options and the possibility of integrating it with other monitoring utilities, makes it an essential component of the Linux system management tool kit.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish