Monitor Disk I/O with iotop in Linux

29/12/2020
Chưa phân loại
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,

  • Thread ID (TID).
  • I/O Priority class/level (PRIO).
  • the owner of the thread with TID (USER).
  • the disk read per second (DISK READ).
  • the disk write per second (DISK WRITE).
  • the percentage of time the thread spent while swapping in (SWAPIN).
  • the percentage of time the thread spent waiting on I/O (IO>).
  • the command the thread is running (COMMAND).

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.

Sandclock IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, Sandclock IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

[Cobbler] Tổng quan về cobbler

Ở bài viết trước đã giới thiệu về PXE cung cấp cho các bạn sự hiểu biết cơ bản về...
30/12/2020

Linux chmod Example

In this quick tutorial, we will see how we can use chmod command in an Ubuntu machine to find, modify and remove user permissions...
28/12/2020

Cinnamon Desktop 3.2.8 released, Install on Ubuntu, Linux Mint

Cinnamon Desktop 3.2.8 recently released, is a Linux desktop which provides advanced innovative features and a traditional...
12/02/2020
Bài Viết

Bài Viết Mới Cập Nhật

Hướng dẫn chuyển đổi windows server windows evaluation to standard và active windows server 2008 + 2012 + 2016 + 2019
26/10/2021

How to Update Ubuntu Linux
24/10/2021

Squid Proxy Manager cài đặt và quản lý Proxy Squid tự động trên ubuntu
20/10/2021

Hướng dẫn cài đặt Apache CloudStack 4.15.2.0
19/10/2021

Hướng dẫn ký file PDF bằng chữ ký số (chữ ký điện tử) và sửa lỗi mới nhất 2021 foxit reader
19/10/2021