如何监控磁盘活动?

如何在Ubuntu上查看我的磁盘活动?例如,我如何监控正在从磁盘读写的内容以及磁盘使用率的百分比?
我正在寻找类似于Windows资源监视器的应用程序。

相关链接:https://serverfault.com/questions/9428/how-can-i-monitor-hard-disk-load-on-linux - Ciro Santilli OurBigBook.com
6个回答

你可以使用iotop。要安装,请打开终端并执行以下命令:
sudo apt-get install iotop

要使用iotop,打开终端并输入以下命令:
sudo iotop

iotop功能实时显示所有磁盘活动,并显示负责该活动的命令以及命令背后的用户,就像资源监视器一样。 点击此处获取更多信息。

enter image description here

除了资源监视器外,htop也具有识别和终止进程的能力。
sudo apt-get install htop

并以监视模式运行htop:
htop

或者,为了获得更多功能和权限,以便完全调试和终止单个进程等。
sudo htop

enter image description here


10你之前询问的是磁盘活动情况,而不是磁盘使用情况。这是对你问题的完美回答。 - xorinzor
你能让 iotop 不列出某个特定的进程,比如 peek,它通过 ffmpg 将 iotop 的输出录制成 .gif 吗? - WinEunuuchs2Unix
1@user25 对于磁盘使用情况,您需要使用不同的命令:df -h -t ext4。这个命令以人类可读的格式打印出来(-h),并假设您正在使用ext4格式(-t ext4)。 - mchid
@WinEunuuchs2Unix sudo iotop $(echo $(ps -A | grep -v ffmpeg | grep -v peek | awk '{print $1}') | sed 's/ / -p /g;s/PID//g') - mchid
1@mchid +1 回覆評論,但我最終使用了嫌疑人的“-p ProcessID”。 - WinEunuuchs2Unix
2022年了。我想要一个图形用户界面(GUI)。跳动的数字并不如简单的图表实用。 - Serhyi Vynohradov
我在htop中看到“它之前是7%繁忙,现在是23%”。它没有显示我需要的信息来决定是否需要更快的硬盘来提高我的工作效率。 - Serhyi Vynohradov

你可以使用 htop。
sudo apt install htop

然后打开htop并进行配置: F2 -> 列 -> 设置IO_RATE(或IO_RATE_READ/IO_RATE_WRITE)-> F10 然后你会看到类似这样的内容:

screenshot


10这应该是问题的答案! - Socrates
3太棒了!这是正确的答案。 - James M
1你的截图显示了DISK R/W,但我在htop中没有看到这个选项。DISK R/W和IO_RATE、IO_RATE_READ/IO_RATE_WRITE之间有什么区别? - user3731622
3在设置中选择IO_RATE列时,会出现DISK R/WIO_RATE是每秒字节的总输入/输出(读取和写入)量。 - RedEyed

你可以试试nmon。
sudo apt-get install nmon

尝试一下:
nmon

以下是输出结果:

enter image description here

Press d = Disk | Press c = CPU Info |Press r = RAM info | Press q = to exit

一顶统领所有的顶!太棒了,谢谢分享。以前没见过这个。 - musicman1979

你可以使用 dstat 程序。要安装它,只需在终端中执行该命令。
sudo apt-get install dstat

使用dstat命令,您将获得一个完整的实时CPU/网络/磁盘活动监视视图,如下所示。
mas@mas-laptop:~ > dstat 
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw 
 15   5  76   4   0   0| 181k  177k|   0     0 |   0    61B|1651  3609 
  5   0  95   0   0   0|   0     0 | 162B 1064B|   0     0 | 500   994 
 15   4  77   4   0   0|   0   292k| 302B   52B|   0     0 | 687  1919 
  6   1  92   1   0   0|   0     0 |   0     0 |   0     0 | 496  1089 
  5   1  94   1   0   1|   0     0 |   0     0 |   0     0 | 422   919
  6   1  93   1   0   0|   0     0 |   0     0 |   0     0 | 517  1181 
  9   2  89   1   0   1|   0     0 |   0     0 |   0     0 | 494  1066

要仅获取最近15分钟的磁盘负载指示器的使用信息,请使用dstat --disk --fs --load命令。下面是一个示例输出。
$ dstat --disk --fs

-dsk/total- --filesystem- ---load-avg---
 read  writ|files  inodes| 1m   5m  15m 
 895k  186k|13728    100k|0.63 0.73 0.84
   0     0 |13728    100k|0.63 0.73 0.84
   0     0 |13728    100k|0.63 0.73 0.84
   0     0 |13728    100k|0.63 0.73 0.84
   0    12k|13728    100k|0.66 0.74 0.84
   0     0 |13728    100k|0.66 0.74 0.84
   0     0 |13728    100k|0.66 0.74 0.84
   0     0 |13728    100k|0.66 0.74 0.84
   0     0 |13728    100k|0.66 0.74 0.84^C

dstat --help具有以下信息:

Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics

Dstat options:
  -c, --cpu              enable cpu stats
     -C 0,3,total           include cpu0, cpu3 and total
  -d, --disk             enable disk stats
     -D total,hda           include hda and total
  -g, --page             enable page stats
  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2
  -l, --load             enable load stats
  -m, --mem              enable memory stats
  -n, --net              enable network stats
     -N eth1,total          include eth1 and total
  -p, --proc             enable process stats
  -r, --io               enable io stats (I/O requests completed)
  -s, --swap             enable swap stats
     -S swap1,total         include swap1 and total
  -t, --time             enable time/date output
  -T, --epoch            enable time counter (seconds since epoch)
  -y, --sys              enable system stats

  --aio                  enable aio stats
  --fs, --filesystem     enable fs stats
  --ipc                  enable ipc stats
  --lock                 enable lock stats
  --raw                  enable raw stats
  --socket               enable socket stats
  --tcp                  enable tcp stats
  --udp                  enable udp stats
  --unix                 enable unix stats
  --vm                   enable vm stats

  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins

  -a, --all              equals -cdngy (default)
  -f, --full             automatically expand -C, -D, -I, -N and -S lists
  -v, --vmstat           equals -pmgdsc -D total

  --float                force float values on screen
  --integer              force integer values on screen

  --bw, --blackonwhite   change colors for white background terminal
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers
  --noupdate             disable intermediate updates
  --output file          write CSV output to file

delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)

关于这个工具的更多信息,请查看以下链接:

1) Dstat主页

2) DiskPerformance社区文档页面


你可以试试Stacer
sudo apt install stacer

看起来如果你想要一个图形界面的话,这似乎是一个不错的选择。它还有许多其他功能。 屏幕截图

首先安装htop:sudo apt install htop 如上面由RedEyed回答的那样,如果你想要查看每个进程的读写速度(以字节/秒为单位),请按照以下步骤操作:设置(F2) --> 列 --> 可用列 --> 选择IO_RATE(如下图所示)

enter image description here

但是如果你想要显示整体磁盘IO的读写情况,就像这样:

enter image description here

去设置(F2)-〉仪表-〉可用仪表-〉磁盘IO,输入添加并选择您希望它在左/右列的位置,然后完成。

enter image description here