哪个程序占用了磁盘IO?
查看一台主机的监控,有时候我们会发现磁盘IO被打满了,这时候怎样定位出是哪个程序大量占用了磁盘IO?
答:使用磁盘IO分析工具。比如iotop,可以监控到读写磁盘的线程和读写速度。
参考文档:
- 在 Linux 中如何使用 iotop 和 iostat 监控磁盘 I/O 活动?
- Linux性能监控命令系列之 iotop
- Monitor Disk I/O with iotop in Linux
- Iotop
安装iotop
yum install iotop
使用iotop
显示当前主机的IO情况iotop
输出内容说明
- Thread ID (TID).
- I/O Priority class/level (PRIO).
- the owner of the thread with TID (USER).
- the disk read per second (DISK READ).
- the disk write per second (DISK WRITE).
- the percentage of time the thread spent while swapping in (SWAPIN).
- the percentage of time the thread spent waiting on I/O (IO>).
- the command the thread is running (COMMAND).
根据线程号查找进程
已知线程号(例如34567),怎样查找对应的进程号?
方法一:直接查找线程号ps -efL | grep 34567
方法二:根据COMMAND关键字(例如nginx)查找进程号,然后查看进程包含的线程号,最后和要查找的线程号进行对比。
1 | ps -ef | grep nginx |