如何在GNU / Linux中记录使用磁盘的进程或内核活动? [英] How can I record what process or kernel activity is using the disk in GNU/Linux?

查看:183
本文介绍了如何在GNU / Linux中记录使用磁盘的进程或内核活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在特定的Debian服务器上,iostat(和类似的)报告正在进行的磁盘写入的意外高容量(以字节为单位)。我无法确定哪些进程正在执行这些写操作。

On a particular Debian server, iostat (and similar) report an unexpectedly high volume (in bytes) of disk writes going on. I am having trouble working out which process is doing these writes.

两个有趣的点:


  1. 尝试一次关闭一个系统服务无济于事。磁盘活动保持相当稳定且出乎意料地高。

  1. Tried turning off system services one at a time to no avail. Disk activity remains fairly constant and unexpectedly high.

尽管写了,但似乎没有占用磁盘上更多的整体空间。

Despite the writing, do not seem to be consuming more overall space on the disk.

这两个让我觉得写作可能是内核正在做的事情,但我不是在交换,所以还不清楚对我来说,Linux可能会尝试写些什么。

Both of those make me think that the writing may be something that the kernel is doing, but I'm not swapping, so it's not clear to me what Linux might try to write.

可以尝试atop:

http://www.atcomputing.nl/Tools/atop/

但是我想避免修补我的内核。

but would like to avoid patching my kernel.

有关如何跟踪此问题的任何想法?

Any ideas on how to track this down?

推荐答案

iotop很好(很棒,实际上)。

iotop is good (great, actually).

如果您有2.6.20之前的内核,则无法使用大多数这些工具。

If you have a kernel from before 2.6.20, you can't use most of these tools.

相反,您可以尝试以下(几乎适用于任何2.6内核IIRC):

Instead, you can try the following (which should work for almost any 2.6 kernel IIRC):

    
sudo -s
dmesg -c
/etc/init.d/klogd stop
echo 1 > /proc/sys/vm/block_dump
rm /tmp/disklog
watch "dmesg -c >> /tmp/disklog"
   CTRL-C when you're done collecting data
echo 0 > /proc/sys/vm/block_dump
/etc/init.d/klogd start
exit (quit root shell)

cat /tmp/disklog | awk -F"[() \t]" '/(READ|WRITE|dirtied)/ {activity[$1]++} END {for (x in activity) print x, activity[x]}'| sort -nr -k2

dmesg -c行清除内核日志。然后关闭记录器,手动(使用watch)转储到磁盘(内存缓冲区很小,这就是我们需要这样做的原因)。让它运行大约五分钟左右,然后按CTRL-c监视进程。关闭日志并重新启动klogd后,最后使用awk的一点点分析结果。

The dmesg -c lines clear your kernel log . The logger is then shut off, manually (using watch) dumped to a disk (the memory buffer is small, which is why we need to do this). Let it run for about five minutes or so, and then CTRL-c the watch process. After shutting off the logging and restarting klogd, analyze the results using the little bit of awk at the end.

这篇关于如何在GNU / Linux中记录使用磁盘的进程或内核活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆