Linux查看IO的工具主要有两个,iostat(集成于sysstat包中)和iotop。前者经常用于查看分区的IO情况,后者常用来查看每个进程的IO占用。
[root@bogon ~]# yum install sysstat
[root@bogon ~]# iostat -x 1 #每隔一秒显示一次
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %
sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
dm-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
dm-1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
hdc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[root@bogon ~]# yum install iotop
[root@bogon ~]# iotop -o #仅显示占用IO的进程
Total DISK READ: 0.00 B/s | Total DISK WRITE: 25.97 K/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
5 be/3 root 0.00 B/s 0.00 B/s 0.00 % 0.88 % [khelper]
534 be/3 root 0.00 B/s 25.17 K/s 0.00 % 0.03 % [kjournald]
187 be/3 root 0.00 B/s 0.00 B/s 0.00 % 0.01 % [cqueue/0]
2945 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % automount --pid-fi~var/run/autofs.pid
2513 be/3 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % auditd
2865 be/4 haldaemo 0.00 B/s 0.00 B/s 0.00 % 0.00 % hald-addon-keyboar~ /dev/input/event0
18 be/3 root 0.00 B/s 0.00 B/s 0.88 % 0.00 % [kblockd/0]
2844 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % hald-runner
2457 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % dhclient -1 -q -lf~ient-eth0.pid eth0
508 be/3 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ata/0]
2970 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % sshd
iotop选项:
–version show program’s version number and exit
-h, –help show this help message and exit
-o, –only only show processes or threads actually doing I/O
-b, –batch non-interactive mode
-n NUM, –iter=NUM number of iterations before ending [infinite]
-d SEC, –delay=SEC delay between iterations [1 second]
-p PID, –pid=PID processes/threads to monitor [all]
-u USER, –user=USER users to monitor [all]
-P, –processes only show processes, not all threads
-a, –accumulated show accumulated I/O instead of bandwidth
-k, –kilobytes use kilobytes instead of a human friendly unit
-t, –time add a timestamp on each line (implies –batch)
-q, –quiet suppress some lines of header (implies –batch)
-p 指定进程ID,显示该进程的IO情况
-u 指定用户名,显示该用户所有的进程IO情况