Esitys

Monitor Disk I/O with iotop in Linux

Monitor Disk I/O with iotop in Linux
On Linux servers, you have lots of processes running and each of these processes are doing some I/O operations. So, these processes are consuming the storage disk bandwidth.

We can use htop command to see a list of all the running processes of our Linux server. But what if we want to monitor how much disk bandwidth each of these processes are consuming? Well, we can use iotop.

iotop is an interactive I/O monitoring tool on Linux just like htop. With iotop, you can easily monitor disk read and write bandwidth usage for each running processed on Linux.

In this article, I am going to show you how to install iotop on popular Linux distributions and how to use iotop to monitor disk read and write bandwidth usage per running process. I will be using Ubuntu 18.04 LTS for the demonstration, but the same commands should work on any modern Linux distributions. So, let's get started.

Installing iotop on Ubuntu:

iotop is available in the official package repository of Ubuntu. So, you can easily download iotop using the APT package manager.

First, update the APT package repository cache with the following command:

$ sudo apt update

Now, install iotop with the following command:

$ sudo apt install iotop

iotop should be installed.

Now, check whether iotop is working with the following command:

$ iotop --version

iotop is working as you can see.

Installing iotop on CentOS 7:

iotop is available in the official package repository of CentOS 7. You can easily install it with the YUM package manager as follows:

$ sudo yum install iotop -y

Basic Usage of iotop:

To monitor the disk usage of each running processes with iotop, run iotop as follows:

$ sudo iotop

As you can see, the iotop interactive window is opened. Here, you can see which process is using the disk.

As you can see on the screenshot below, on the top left side, the total disk read speed/bandwidth is displayed. The same way, on the top right side, the total disk write speed/bandwidth is displayed.

As you can see, iotop displays columns for,

For most of the cases, the Thread ID (TID) is equivalent to Process ID (PID).

Displaying Processes Doing I/O Operations Only:

By default, iotop shows all the running processes whether they are doing I/O operations or not. So, the list is very long. It is harder to find the processes we need and monitor them.

Luckily, iotop lets you display only the processes that are doing I/O operations. To do that, you can use the -o or -only option of iotop.

To display only the processes doing I/O operations, run iotop as follows:

$ sudo iotop -o

Or

$ sudo iotop --only

As you can see, the process with TID 1345 and 1957 are doing I/O operations right now.

This is the command that I am running to simulate I/O operations in this article.

$ dd if=/dev/urandom of=iotest.img bs=1M count=1000

NOTE: If you haven't started iotop with the -o or -only option, you can still switch to this mode by pressing the o key on your keyboard. You can toggle between these 2 modes of iotop using the o key.

Displaying Total I/O Usage Per Process:

iotop also lets you monitor how much disk reads and disk writes in total each processes have done after iotop started as well. To do that, you have to use the -a or -accumulated option. You can also use it with the -o or -only option as well.

For example,

$ sudo iotop -ao

As you can see, the total disk reads and disk writes per process is displayed.

Displaying PID instead of TID:

As I've stated earlier, Thread ID (TID) is the same as Process ID (PID) most of the time. You can use these interchangeably. But if you really want to be sure that you're working with exactly process ID (PID), then iotop has the -P or -processes option that you can use to change the default TID column to PID column.

To display PID column instead of TID column, run iotop as follows:

$ sudo iotop -P

Or

$ sudo iotop --processes

As you can see, the TID column is replaced by the PID column.

Filtering iotop Processes:

You can filter iotop processes based on process ID (PID), thread ID (TID) and the processed owner (USER).

For example, if you want to monitor the disk I/O of the processes with the PID 2024 and 2035 only, you would run iotop as follows:

$ sudo iotop -P -p 2024 -p 2035

As you can see, only the processes with the PID 2024 and 2035 are being monitored.

If you wanted to monitor the disk I/O of the threads with the TID 2024 and 2035 only, you would run iotop as follows:

$ sudo iotop -P -p 2024 -p 2035

Again, let's say, you want to monitor the disk I/O of the processes running as the user shovon. To do that, run iotop as follows:

$ sudo iotop -P -u shovon

As you can see, only the processes running as the user shovon is displayed.

If you want to monitor multiple users at once, you can do that as well.

For example, to monitor disk I/O of all the processes that the users shovon and lily are running, run iotop as follows:

$ sudo iotop -P -u shovon -u lily

So, that's basically how you use iotop to monitor disk I/O in Linux. Thanks for reading this article.

HD Remastered Games for Linux that Never had a Linux Release Earlier
Many game developers and publishers are coming up with HD remaster of old games to extend the life of franchise, please fans requesting compatibility ...
Kuinka käyttää AutoKey-toimintoa Linux-pelien automatisointiin
AutoKey on työpöydän automaatioapuohjelma Linuxille ja X11: lle, ohjelmoitu Python 3, GTK ja Qt. Komentosarjojen ja MACRO-toimintojen avulla voit auto...
Kuinka näyttää FPS-laskuri Linux-peleissä
Linux-pelaaminen sai suuren työn, kun Valve ilmoitti Linux-tuesta Steam-asiakkaalle ja heidän peleilleen vuonna 2012. Siitä lähtien monet AAA- ja indi...