How To Monitor Disk I/O Activity Using iotop And iostat Commands In Linux?
======
Do you know what are the tools we can use for troubleshooting or monitoring real-time disk activity in Linux?
If **[Linux system performance][1]** gets slow down we may use **[top command][2]** to see the system performance.
It is used to check what are the processes are consuming high utilization on server.
It’s common for most of the Linux administrator.
It’s widely used by Linux administrator in the real world.
If you don’t see much difference in the process output still you have an option to check other things.
I would like to advise you to check `wa` status in the top output because most of the time the server performance will be degraded due to high I/O Read and Write on hard disk.
If it’s high or fluctuation, it could be a cause. So, we need to check I/O activity on hard drive.
We can monitory disk I/O statistics for all disks and file system in Linux system using `iotop` and `iostat` commands.
### What Is iotop?
iotop is a top-like utility for displaying real-time disk activity.
iotop watches I/O usage information output by the Linux kernel and displays a table of current I/O usage by processes or threads on the system.
It displays the I/O bandwidth read and written by each process/thread. It also displays the percentage of time the thread/process spent while swapping in and while waiting on I/O.
Total DISK READ and Total DISK WRITE values represent total read and write bandwidth between processes and kernel threads on the one side and kernel block device subsystem on the other.
Actual DISK READ and Actual DISK WRITE values represent corresponding bandwidths for actual disk I/O between kernel block device subsystem and underlying hardware (HDD, SSD, etc.).
### How To Install iotop In Linux?
We can easily install it with help of package manager since the package is available in all the Linux distributions repository.
For **`Fedora`** system, use **[DNF Command][3]** to install iotop.
```
$ sudo dnf install iotop
```
For **`Debian/Ubuntu`** systems, use **[APT-GET Command][4]** or **[APT Command][5]** to install iotop.
```
$ sudo apt install iotop
```
For **`Arch Linux`** based systems, use **[Pacman Command][6]** to install iotop.
```
$ sudo pacman -S iotop
```
For **`RHEL/CentOS`** systems, use **[YUM Command][7]** to install iotop.
```
$ sudo yum install iotop
```
For **`openSUSE Leap`** system, use **[Zypper Command][8]** to install iotop.
```
$ sudo zypper install iotop
```
### How To Monitor Disk I/O Activity/Statistics In Linux Using iotop Command?
There are many options are available in iotop command to check varies statistics about disk I/O.
Run the iotop command without any arguments to see each process or thread current I/O usage.
```
# iotop
```
[![][9]![][9]][10]
If you would like to check which process are actually doing IO then run the iotop command with `-o` or `--only` option.
```
# iotop --only
```
[![][9]![][9]][11]
**Details:**
* **`IO:`** It shows I/O utilization for each process, which includes disk and swap.
* **`SWAPIN:`** It shows only the swap usage of each process.
### What Is iostat?
iostat is used to report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions.
The iostat command is 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 command generates reports that can be used to change system configuration to better balance the input/output load between physical disks.
All statistics are reported each time the iostat command is run. The report consists of a CPU header row followed by a row of CPU statistics.
On multiprocessor systems, CPU statistics are calculated system-wide as averages among all processors. A device header row is displayed followed by a line of statistics for each device that is configured.
The iostat command generates two types of reports, the CPU Utilization report and the Device Utilization report.
### How To Install iostat In Linux?
iostat tool is part of sysstat package so, We can easily install it with help of package manager since the package is available in all the Linux distributions repository.
For **`Fedora`** system, use **[DNF Command][3]** to install sysstat.
```
$ sudo dnf install sysstat
```
For **`Debian/Ubuntu`** systems, use **[APT-GET Command][4]** or **[APT Command][5]** to install sysstat.
```
$ sudo apt install sysstat
```
For **`Arch Linux`** based systems, use **[Pacman Command][6]** to install sysstat.
```
$ sudo pacman -S sysstat
```
For **`RHEL/CentOS`** systems, use **[YUM Command][7]** to install sysstat.
```
$ sudo yum install sysstat
```
For **`openSUSE Leap`** system, use **[Zypper Command][8]** to install sysstat.
```
$ sudo zypper install sysstat
```
### How To Monitor Disk I/O Activity/Statistics In Linux Using sysstat Command?
There are many options are available in iostat command to check varies statistics about disk I/O and CPU.
Run the iostat command without any arguments to see complete statistics of the system.
```
# iostat
Linux 4.19.32-1-MANJARO (daygeek-Y700) Thursday 18 April 2019 _x86_64_ (8 CPU)
Run the iostat command with certain interval then use the following format. In this example, we are going to capture totally two reports at five seconds interval.
```
# iostat [Interval] [Number Of Reports]
# iostat 5 2
Linux 4.19.32-1-MANJARO (daygeek-Y700) Thursday 18 April 2019 _x86_64_ (8 CPU)