Monitoring disk activity on Linux is important for understanding system performance, especially during high data throughput. Disk Input/Output (I/O) processes, such as reading and writing, can affect system response times and overall efficiency. When troubleshooting performance issues, checking disk activity can provide insights beyond just focusing on CPU usage.

Several tools are available in Linux to track disk activity. Commonly used options include iostat, iotop, and ioping. These tools monitor different aspects of disk usage, such as block device performance, real-time process activity, and disk latency. They can all be installed and executed from the terminal.

By monitoring disk activity, you can identify performance bottlenecks caused by excessive disk usage. This helps improve overall system performance, especially in environments that rely on heavy disk operations like databases or servers. The following steps outline how to monitor disk activity using these tools.

Steps to monitor disk activity on Linux:

  1. Open the terminal on your Linux system.
  2. Install the sysstat package, which includes the iostat tool.
    $ sudo apt update && sudo apt install --assume-yes sysstat # Ubuntu and Debian derivatives
    $ sudo yum install --assumeyes sysstat # Red Hat and CentOS derivatives
  3. Run iostat to display the I/O activity for all block devices on your system.
    $ iostat
    Linux 5.8.0-48-generic (host) 	Jumaat 09 Apr 2021 	_x86_64_	(2 CPU)
    
    avg-cpu:  %user   %nice %system %iowait  %steal   %idle
               0.25    0.01    0.18    0.01    0.00   99.54
    
    Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd
    loop0             0.00         0.02         0.00         0.00       1080          0          0
    loop1             0.00         0.01         0.00         0.00        359          0          0
    loop10            0.01         0.27         0.00         0.00      13555          0          0
    loop11            0.00         0.00         0.00         0.00         14          0          0
    loop2             0.00         0.02         0.00         0.00       1095          0          0
    loop3             0.00         0.01         0.00         0.00        348          0          0
    loop4             0.00         0.01         0.00         0.00        347          0          0
    loop5             0.00         0.02         0.00         0.00       1073          0          0
    loop6             0.00         0.01         0.00         0.00        350          0          0
    loop7             0.01         0.28         0.00         0.00      13967          0          0
    loop8             0.00         0.01         0.00         0.00        362          0          0
    loop9             0.00         0.01         0.00         0.00        358          0          0
    sda               2.95        16.00        95.17         0.00     800785    4762513          0
    sdb               0.00         0.06         0.00         0.00       3233         12          0
    sr0               0.00         0.00         0.00         0.00          2          0          0

    The iostat output shows statistics for CPU usage and I/O statistics for each device.

  4. Monitor specific disk activity by specifying a device with iostat and set an interval for continuous monitoring.
    $ iostat /dev/sda -y 5
    Linux 5.8.0-48-generic (host) 	Sabtu 10 Apr 2021 	_x86_64_	(2 CPU)
    
    
    avg-cpu:  %user   %nice %system %iowait  %steal   %idle
               3.67    0.00    2.73    0.00    0.00   93.60
    
    Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd
    sda               0.40         0.00         2.40         0.00          0         12          0
    
    
    avg-cpu:  %user   %nice %system %iowait  %steal   %idle
               4.73    0.00    2.52    0.00    0.00   92.75
    
    Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd
    sda               0.00         0.00         0.00         0.00          0          0          0
    
    
    avg-cpu:  %user   %nice %system %iowait  %steal   %idle
               3.70    0.00    3.28    0.00    0.00   93.02
    
    Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd
    sda              31.00         0.00       169.60         0.00          0        848          0
  5. Install iotop to track real-time I/O usage by active processes.
    $ sudo apt update && sudo apt install --assume-yes iotop # Ubuntu and Debian derivatives
    $ sudo yum install --assumeyes iotop # Red Hat and CentOS derivatives
  6. Run iotop to see disk read and write operations for all running processes.
    $ sudo iotop
    [sudo] password for user:
    Total DISK READ:         0.00 B/s | Total DISK WRITE:         0.00 B/s
    Current DISK READ:       0.00 B/s | Current DISK WRITE:       0.00 B/s
        TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                                                                                                                                                                                                                                                                                                            
          1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % init splash
          2 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kthreadd]
          3 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_gp]
          4 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_par_gp]
          6 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/0:0H]
          9 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [mm_percpu_wq]
         10 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/0]
         11 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_sched]
         12 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/0]
         13 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [idle_inject/0]
         14 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [cpuhp/0]
         15 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [cpuhp/1]
         16 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [idle_inject/1]
         17 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/1]
         18 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/1]
         20 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/1:0H-kblockd]
         21 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kdevtmpfs]
         22 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [netns]
         23 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_tasks_kthre]
         24 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_tasks_rude_]
         25 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_tasks_trace]
  7. Use iotop to observe only processes with active I/O.
    $ sudo iotop -o
    Total DISK READ:         0.00 B/s | Total DISK WRITE:       125.32 K/s
    Current DISK READ:       0.00 B/s | Current DISK WRITE:     148.82 K/s
        TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                                                                                                                                                                                                                                                                                                            
       7165 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.04 % [kworker/u256:1-events_freezable_power_]
        316 be/3 root        0.00 B/s  125.32 K/s  0.00 %  0.03 % [jbd2/sda3-8]
  8. Use iotop with the -o option to filter only processes currently using I/O.
    $ sudo iotop -o
  9. Install the ioping tool to check disk latency.
    $ sudo apt update && sudo apt install --assume-yes ioping # Ubuntu and Debian derivatives
    $ sudo yum install --assumeyes ioping # Red Hat and CentOS derivatives
  10. Run ioping to measure the performance and latency of a specific disk or directory.
    $ sudo ioping /dev/sda
    4 KiB <<< /dev/sda (block device 20 GiB): request=1 time=1.13 ms (warmup)
    4 KiB <<< /dev/sda (block device 20 GiB): request=2 time=1.50 ms
    4 KiB <<< /dev/sda (block device 20 GiB): request=3 time=2.49 ms
    4 KiB <<< /dev/sda (block device 20 GiB): request=4 time=1.11 ms
    4 KiB <<< /dev/sda (block device 20 GiB): request=5 time=807.4 us
    4 KiB <<< /dev/sda (block device 20 GiB): request=6 time=2.02 ms
Discuss the article:

Comment anonymously. Login not required.