centos7 在某一段时间监控报警磁盘使用率达99%,由于监控属于概要形式信息,没有快照信息的监控(能发现某进程的I/O,CPU消耗情况),所以需要在服务器上去定时执行统计命令获取快照信息。
需要通过iostat -dx -k去查看avgqu-sz、await、svctm、%util;
sar -u查看%iowait、%user;
pidstat -d 查看进程I/O读写的快照信息
步骤
- 生成统计信息文件
cat>/tmp/at_task.sh/tmp/pidstat_`date +%F_%T`.log 2>& 1 &
sar -u 2 >/tmp/sar_`date +%F_%T`.log 2>& 1 &
while [ 1 ];do echo -n `date +%T` >>/tmp/iostat_`date +%F` 2>& 1 && iostat -dx -k 1 1 >>/tmp/iostat_`date +%F` 2>& 1; sleep 2; done &
EOF
在while循环中使用iostat的原因是要输出
date +%T
时间,不然只有数据,没有时间信息也没有什么用
- 使用at 命令定时执行
at 15:14 today -f /tmp/at_task.sh
出现错误
Can’t open /var/run/atd.pid to signal atd. No atd running?
重启atd服务
service atd restart
重新开启at定时任务
at 15:14 today -f /tmp/at_task.sh
job 2 at Wed Mar 13 15:14:00 2019
得到如下快照信息
iostat
15:13:35Linux 3.10.0-862.14.4.el7.x86_64 (ip-xxxxx) 03/13/2019 _x86_64_ (4 CPU)
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
vda 0.12 0.07 17.31 19.41 580.79 90.52 36.57 0.09 2.39 4.42 0.57 0.72 2.63
scd0 0.00 0.00 0.00 0.00 0.00 0.00 6.00 0.00 0.28 0.28 0.00 0.25 0.00
sar
03:14:00 PM CPU %user %nice %system %iowait %steal %idle
03:14:02 PM all 0.25 0.00 0.38 0.00 0.00 99.37
03:14:04 PM all 1.25 0.13 0.63 0.00 0.00 97.99
03:14:06 PM all 0.25 0.13 0.50 0.00 0.00 99.12
03:14:08 PM all 0.50 0.00 0.50 0.63 0.00 98.37
pidstat
03:14:00 PM UID PID kB_rd/s kB_wr/s kB_ccwr/s Command
03:14:02 PM 5700 9089 0.00 6.00 0.00 uxxx
03:14:02 PM 5700 9140 0.00 6.00 0.00 uxxx
03:14:02 PM 5700 9292 0.00 10.00 0.00 uxxx
03:14:02 PM 0 18084 0.00 2.00 0.00 bash
kill 掉收集信息的命令
ps -ef | egrep 'iostat|sar|pidstat|while' | grep -v grep | awk '{print $2}' | xargs -l kill
但ps -ef | egrep 命令没有获取到while循环的pid,不kill掉该while循环,就会一直对/tmp/iostat_2019-03-13写数据-_-
通过lsof 没有定位到打开文件的进程
lsof /tmp/iostat_2019-03-13
[root@ip-10-186-60-117 ~]#
[root@ip-10-186-60-117 ~]#
通过lsof 可以定位到打开mysql-error.log的进程
lsof /opt/mysql/data/5690/mysql-error.log
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 12858 actiontech-universe 1w REG 253,1 6345 20083533 /opt/mysql/data/5690/mysql-error.log
mysqld 12858 actiontech-universe 2w REG 253,1 6345 20083533 /opt/mysql/data/5690/mysql-error.log
可见,某进程只有一只持有某文件的inode,才可以通过lsof查看文件在被那些进程使用
服务器租用托管,机房租用托管,主机租用托管,https://www.e1idc.com