« Back to File systems: Frequently Asked Questions

How to monitor disk activity (I/O) on Linux

How to monitor disk activity (I/O) on Linux?

Use tools like iotop, sar, vmstat, and iostat to discover how busy a disk is and which processes are responsible.

iotop

To find out what processes are actively using the disk, we need to monitor disk I/O. Commands that can be used include iostat, iotop, and vmstat.

Examples using iotop

Run the iotop command without any parameters to see an interactive display of the total disk read and write speeds, including the processes responsible for initiating these read or write actions.

# iotop
  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  GRAPH[R+W]▽      COMMAND                                  [T]
     1   be/4 root         0.00 B/s    0.00 B/s                  systemd                                   ▲
     2   be/4 root         0.00 B/s    0.00 B/s                  kthreadd                                  █
     3   be/0 root         0.00 B/s    0.00 B/s                  rcu_gp                                    █
     4   be/0 root         0.00 B/s    0.00 B/s                  rcu_par_gp                                █
     5   be/0 root         0.00 B/s    0.00 B/s                  slub_flushwq                              █
     6   be/0 root         0.00 B/s    0.00 B/s                  netns                                     █

Use ‘q’ to quit.

Non-interactive usage of iotop

Another option is to run iotop non-interactively. This is achieved by using the --batch option. To make it automatically stop after a few times, we can provide a the --iter=NUMBER option.

# iotop --batch --iter=3

To reduce the output further, we can tell the program to queue the activity by adding a delay with --delay=SECONDS. Instead of a default delay of a single second, we can take a longer period. We need at least two iterations to gather the information. Typically only the active processes are interesting, which we can filter out using the --only option.

# iotop --batch --only --delay=30 --iter=2

Disk activity per device

vmstat

To learn about the most active devices, use the vmstat command. To see a single moment in time, run the command without any parameters.

vmstat

To queue up disk activity and get a better idea on the most active device, let the tool perform two measures with a time interval (e.g. 30 seconds).

# vmstat --disk 30 2
disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
loop0    276      0    3446      32      0      0       0       0      0      0
loop1   1525      0  131252     192      0      0       0       0      0      4
loop2    361      0   10116      97      0      0       0       0      0      0
loop3    247      0    3484      29      0      0       0       0      0      0
loop4    410      0   10748     141      0      0       0       0      0      0
loop5    404      0    7118      48      0      0       0       0      0      0
loop6    175      0    2276      23      0      0       0       0      0      0
loop7      0      0       0       0      0      0       0       0      0      0
sr0        5      0       2       0      0      0       0       0      0      0
sda   311804  43728 22006273   97600 1922715 958862 116556904 1651642      0   1913
dm-0  341315      0 19843630  120412 2847459      0 113510856 2880140      0   1894
loop0    276      0    3446      32      0      0       0       0      0      0
loop1   1525      0  131252     192      0      0       0       0      0      4
loop2    361      0   10116      97      0      0       0       0      0      0
loop3    247      0    3484      29      0      0       0       0      0      0
loop4    410      0   10748     141      0      0       0       0      0      0
loop5    404      0    7118      48      0      0       0       0      0      0
loop6    175      0    2276      23      0      0       0       0      0      0
loop7      0      0       0       0      0      0       0       0      0      0
sr0        5      0       2       0      0      0       0       0      0      0
sda   311804  43728 22006273   97600 1922737 958875 116557312 1651690      0   1913
dm-0  341315      0 19843630  120412 2847494      0 113511264 2880252      0   1894

iostat

Another tool that provides insights like vmstat is the the iotop command. By default with colored output and easier to read. Like with other tools we can define a delay and number of measurements.

# iostat 30 2

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.20    0.01    0.04    0.01    0.01   99.73

Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd
dm-0              0.34         1.04         5.92         8.96    9922115   56756396   85913152
loop0             0.00         0.00         0.00         0.00       1723          0          0
loop1             0.00         0.01         0.00         0.00      65626          0          0
loop2             0.00         0.00         0.00         0.00       5058          0          0
loop3             0.00         0.00         0.00         0.00       1742          0          0
loop4             0.00         0.00         0.00         0.00       5374          0          0
loop5             0.00         0.00         0.00         0.00       3559          0          0
loop6             0.00         0.00         0.00         0.00       1138          0          0
sda               0.24         1.15         6.08         9.42   11003436   58279420   90309104
sr0               0.00         0.00         0.00         0.00          1          0          0


avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.43    0.00    0.17    0.10    0.03   99.27

Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd
dm-0              1.23         0.00         8.00         0.00          0        240          0
loop0             0.00         0.00         0.00         0.00          0          0          0
loop1             0.00         0.00         0.00         0.00          0          0          0
loop2             0.00         0.00         0.00         0.00          0          0          0
loop3             0.00         0.00         0.00         0.00          0          0          0
loop4             0.00         0.00         0.00         0.00          0          0          0
loop5             0.00         0.00         0.00         0.00          0          0          0
loop6             0.00         0.00         0.00         0.00          0          0          0
sda               0.73         0.00         8.00         0.00          0        240          0
sr0               0.00         0.00         0.00         0.00          0          0          0

When reviewing the data, be aware that the first set of data shows a total number per device. The second one shows the difference, which makes it a great tool to see what happened in the last 30 seconds.

Other questions related to Linux file systems

Related articles

Like to learn more? Here is a list of articles within the same category or having similar tags.

Feedback

Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon