Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Using iostat

Introduction

In the world of Linux system administration, monitoring system performance is crucial. One of the tools available for this task is iostat. This command-line utility reports CPU and input/output statistics for devices and partitions. By understanding how to use iostat, you can gain insights into the performance of your system's storage subsystem.

Installing iostat

Before using iostat, you need to ensure it is installed on your system. It is part of the sysstat package. You can install it using your package manager.

On Debian-based systems (e.g., Ubuntu):

sudo apt-get install sysstat

On Red Hat-based systems (e.g., CentOS):

sudo yum install sysstat

Basic Usage

The simplest way to use iostat is to run it without any options. This will provide a summary of CPU and I/O statistics since the last system boot.

iostat
Linux 4.15.0-112-generic (hostname) 	09/29/2020 	_x86_64_	(4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.29    0.00    0.45    0.15    0.00   98.10

Device             tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               1.12        13.45        40.65    1048576    3145728
                    

Understanding the Output

The iostat output is divided into two sections: CPU statistics and device statistics.

CPU Statistics

The CPU statistics section shows the percentage of CPU utilization for different categories:

  • %user: Time spent on user-level processes.
  • %nice: Time spent on user-level processes with a niceness value.
  • %system: Time spent on system-level processes.
  • %iowait: Time spent waiting for I/O operations to complete.
  • %steal: Time spent in involuntary wait by virtual CPU while the hypervisor is servicing another virtual processor.
  • %idle: Time spent idle.

Device Statistics

The device statistics section provides information about I/O operations for each device:

  • tps: Transactions per second.
  • kB_read/s: Kilobytes read per second.
  • kB_wrtn/s: Kilobytes written per second.
  • kB_read: Total kilobytes read.
  • kB_wrtn: Total kilobytes written.

Advanced Usage

While the basic usage provides a useful snapshot, iostat offers several options for more detailed analysis.

Specifying an Interval

You can specify an interval (in seconds) for iostat to provide continuous updates. For example, to get updates every 2 seconds:

iostat 2

Specifying the Number of Reports

You can also specify the number of reports you want. For example, to get 3 updates at 2-second intervals:

iostat 2 3

Monitoring Specific Devices

If you're interested in monitoring a specific device, you can specify the device name. For example, to monitor the sda device:

iostat -d sda
Linux 4.15.0-112-generic (hostname) 	09/29/2020 	_x86_64_	(4 CPU)

Device             tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               1.12        13.45        40.65    1048576    3145728
                    

Combining Options

You can combine different options to tailor the output to your needs. For example, to get 5 updates for the sda device at 2-second intervals:

iostat -d sda 2 5

Conclusion

The iostat utility is a powerful tool for monitoring the performance of your system's storage subsystem. By understanding and utilizing its various options, you can gain valuable insights into CPU and I/O statistics, helping you to diagnose performance issues and optimize your system.