A Central Processing Unit or CPU is the brain of the computer. All of processing command is run here. Input / Ouput or I/O also play critical roles. The disks is used to provide data to processor and keeps the data which has been processed by CPU. One of the methods for measuring processor utilization and I/O utilization is to use iostat command. From its utilization we can decide do we need to add more resources or not.
What is iostat
iostat command is a command that used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates. The iostat create reports that can be used to change system configuration to better balance the input/output between physical disks.
iostat is included in sysstat package. If you don’t have it, you need to install first.
On RedHat / CentOS / Fedora
# yum install sysstat
On Debian / Ubuntu / Linux Mint
$ sudo apt-get install sysstat
How to run iostat
To run it, just type iostat in your console. Here’s a sample.
Here’s how to read iostat reports
The first section contains CPU report
The second section contains device utilization report
Capture iostat with kilobytes or megabytes
By default iostat measure the I/O system with bytes unit. To make it easier to read, we can convert iostat to show us reports in kilobytes or megabytes unit. Just add -k parameter to create reports with kilobytes unit and -m parameter to create reports with megabytes unit.
$ iostat -k
$ iostat -m
To extend the reports we can use -x parameter after iostat command.
$ iostat -x
Using iostat with delay
Same with vmstat, as a statistic tool the best way to use it is with delay parameter. With delay, we can see what’s the trend. Here are some samples to run iostat with delay.
Run iostat with kilobytes unit, 2 seconds interval with 3 times reports
$ iostat -k 2 3
Show CPU only report with 3 seconds interval and 6 times reports
$ iostat -c 3 6
Show hda2 and hda6 device only report with 2 seconds interval and 4 times reports
$ iostat -d hda2 hda6 2 4
iostat use these files to create reports.
/proc/stat which contains system statistics
/proc/partitions which contains disk statistics (for pre 2.5 kernel that have been patched)
/proc/diskstats contains disks statistics (for post 2.5 kernel)
/sys which contains statistics for block devices (post 2.5 kernel)
With vmstat to monitor memory usage, iostat to monitor CPU usage and I/O system then we have a complete tool to monitor three critical components in your machine. One of the advantage of those tools is you can run them without root privilege. You can dig it deeper by exploring iostat manual page. Just type man iostat in your console to bring iostat manual page.