Poison

iotop

iotop watches I/O usage information output by the Linux kernel (requires 2.6.20 or later) and displays a table of current I/O usage by processes or threads on the system. At least the CONFIG_TASK_DELAY_ACCT and CONFIG_TASK_IO_ACCOUNTING options need to be enabled in your Linux kernel build configuration, these options depend on CONFIG_TASKSTATS.

iotop displays columns for the I/O bandwidth read and written by each process/thread during the sampling period. It also displays the percentage of time the thread/process spent while swapping in and while waiting on I/O. For each process, its I/O priority (class/level) is shown. In addition, the total I/O bandwidth read and written during the sampling period is displayed at the top of the interface.

Use the left and right arrows to change the sorting, r to reverse the sorting order, o to toggle the –only option, p to toggle the –processes option, a to toggle the –accumulated option, q to quit or i to change the priority of a thread or a process’ thread(s). Any other key will force a refresh.

我一般使用 iotop -o 定位高 IO 使用率的进程或线程,注意在容器内使用需要获得对应权限。如果是 JVM 线程,则可以拉取一次栈帧然后通过 Thread.getId() | Poison 一文中提到的线程映射方式定位至 JVM 线程栈帧。

同理,htop 等命令经过配置后也可以查看 IO 等监控数据。

Reference

iotop(1) - Linux man page
hard drive - How to monitor disk activity? - Ask Ubuntu