2015年(68)
分类: 系统运维
2015-08-31 19:23:18
如果内核版本是2.6.20及以上的,可以用iotop,dstat等如:
[root@localhost ~]# uname -r
2.6.32-131.0.15.el6.x86_64
//iotop 可以实时看到每个进程的磁盘读写情况
[root@localhost ~]# iotop
Total DISK READ: 67.99 M/s | Total DISK WRITE: 408.20 K/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
31390 be/4 root 67.89 M/s 67.89 M/s 0.00 % 90.77 % cp -i /rhel6/ ./ -r
1386 be/3 root 0.00 B/s 3.43 K/s 0.00 % 7.88 % [jbd2/sda2-8]
599 be/3 root 0.00 B/s 99.48 K/s 0.00 % 5.18 % [jbd2/sda3-8]
10445 be/4 nagios 0.00 B/s 30.87 K/s 0.00 % 0.00 % nagios -d /usr/local/nagios/etc/nagios.cfg
//dstat 只显示磁盘IO最高的进程
[root@localhost ~]# rpm -q dstat
dstat-0.7.0-1.el6.noarch
## 我系统自带的版本0.6.7没有top-io等模块,升级为0.7.0
[root@localhost ~]# dstat -t --top-bio --top-io
[root@localhost ~]# dstat -t --top-bio --top-io
----system---- ----most-expensive---- ----most-expensive----
date/time | block i/o process | i/o process
26-07 15:23:05|init 119B 19k|init 82k 15k
26-07 15:23:06|named 0 4096B|openvpn 9608B 7699B
26-07 15:23:07| |openvpn 8850B 7588B
26-07 15:23:08| |openvpn 13k 12k
26-07 15:23:09| |init 31k 1591B
26-07 15:23:10|jbd2/sda3-8 0 12k|openvpn 11k 6313B
26-07 15:23:11| |openvpn 6442B 4247B
26-07 15:23:12| |openvpn 3909B 3269B
26-07 15:23:13| |openvpn 5045B 3207B
26-07 15:23:14| |irqbalance 15k 0
26-07 15:23:15|jbd2/sda3-8 0 48k|openvpn 8483B 1565B
26-07 15:23:16| |openvpn 5109B 3546B
26-07 15:23:17|cp 24M 24M|cp 27M 27M
如果内核版本是2.6.20以下的,I/O accounting 支持没有编进内核,用iotop会有下面的报错信:
[root@localhost ~]# uname -r
2.6.18-128.el5
[root@localhost ~]# iotop
Could not run iotop as some of the requirements are not met:
- Linux >= 2.6.20 with
- I/O accounting support (CONFIG_TASKSTATS, CONFIG_TASK_DELAY_ACCT, CONFIG_TASK_IO_ACCOUNTING)
可以用下面的方法来获得IO情况:
//下载iodump
[root@localhost ~]# wget
//配置系统
[root@localhost ~]# dmesg -c
[root@localhost ~]# /etc/init.d/klogd stop
[root@localhost ~]# echo 1 > /proc/sys/vm/block_dump //使内核记录系统每次的IO操作
//收集数据
[root@localhost ~]#while true; do sleep 1; dmesg -c; done | perl iodump
## 按CTRL+C 结束收集并显示结果
# Caught SIGINT.
TASK PID TOTAL READ WRITE DIRTY DEVICES
kjournald 479 5383 0 5383 0 cciss/c0d0p4
pdflush 12556 3342 0 3342 0 cciss/c0d0p4, cciss/c0d0p2
mysqld 3637 3124 1 3123 0 cciss/c0d0p4
mysqld 14090 2122 0 2122 0 cciss/c0d0p4
mysqld 22008 1543 1 1542 0 cciss/c0d0p4
mysqld 24060 1328 2 1326 0 cciss/c0d0p4
mysqld 9333 872 0 872 0 cciss/c0d0p4
mysqld 9171 848 0 848 0 cciss/c0d0p4
mysqld 24948 473 2 471 0 cciss/c0d0p4
mysqld 6234 171 0 171 0 cciss/c0d0p4
kjournald 1695 100 0 100 0 cciss/c0d0p2
python 8702 75 0 75 0 cciss/c0d0p4
python 14100 12 12 0 0 cciss/c0d0p4, cciss/c0d0p2
//恢复系统配置
[root@localhost ~]#echo 0 > /proc/sys/vm/block_dump
[root@localhost ~]#/etc/init.d/klogd start