是否可以监视linux下所有进程对文件系统的所有写入访问



是否可以监视linux下所有进程对文件系统的所有写入访问?

我有一些不同的挂载文件系统。其中很多都是诱惑者。

我对除tempfs,devtmpfs等之外的所有对根文件系统的写入都感兴趣。

我正在寻找可以输出的东西:<PID xy> write n Bytes to /targe/filepath. 什么监控工具可以列出所有这些写入系统调用?可以按挂载点过滤吗?

iotop(内核版本2.6.20或更高版本(或dstat可以为您提供帮助。 例如iotop -o -b -d 10就像在这个类似的线程中讨论的那样。

/proc/diskstats 包含所有块设备的数据。

https://www.kernel.org/doc/Documentation/iostats.txt

The /proc/diskstats file displays the I/O statistics of block devices. Each line contains the following 14 fields:
1 - major number
2 - minor mumber
3 - device name
4 - reads completed successfully
5 - reads merged
6 - sectors read
7 - time spent reading (ms)
8 - writes completed
9 - writes merged
10 - sectors written
11 - time spent writing (ms)
12 - I/Os currently in progress
13 - time spent doing I/Os (ms)
14 - weighted time spent doing I/Os (ms)
For more details refer to Documentation/iostats.txt

您可以编写 SystemTap 脚本来监视文件系统操作。也许你可以访问Brendan D. Gregg的博客,那里有很多监控工具。

fatrace (文件活动跟踪(

fatrace 报告所有正在运行的进程的文件访问事件(打开、读取、写入、关闭(。它的主要目的是找到不断不必要地唤醒磁盘的进程,从而防止一些省电。

运行时,它以以下格式为每个事件输出一行:

<timestamp> <processName(id)>: <accessType> </path/to/file>

例如:

23:10:21.375341 Plex Media Serv(2290): W /srv/dev-disk-by-uuid-UID/Plex/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log

从中您可以轻松获得所有必要的信息

  • 来自 --timestamp 选项的时间戳

  • 进程名称(访问者(

  • 文件操作(O型笔R-读取W-rite C-lose(

  • 文件路径(写入位置(。

  • 您可以使用--current-mount将搜索范围限制为仅记录当前目录的分区/挂载事件。

    • 因此,只需先cd到与您的旋转硬盘相对应的卷中,然后使用--current-mount选项运行ftrace。
  • 如果没有此选项,则会监视所有(真实(分区/挂载点。

非常实用

有了它,我很容易发现,当没有人访问 NAS 并且没有即将运行的维护任务时,我的 NAS 磁盘也 24/7 全天候旋转的原因是 Plex 媒体服务器不必要的日志记录。

最新更新