Linux > 做了一个定时记录cpu/mem占用的程序

2014-10-24

客服某个服务器老是cpu100%跑慢,爬日志又爬不出问题,写了个代码记录日志

#!/bin/bash
date >> /var/log/ps.log
ps -e -o pcpu,pmem,args --sort=pcpu | cut -d" " -f1-5 | tail >> /var/log/ps.log

放在/etc/cron.hourly下。

日志形式大概是

Fri Oct 24 15:01:01 CST 2014
0.0 3.9 /usr/sbin/httpd
0.0 2.8 /usr/sbin/httpd
0.0 0.1 CROND
0.0 0.1 /bin/bash
0.0 0.1 /bin/bash
0.0 0.0 awk
0.0 0.0 ps
0.0 0.0 cut
0.0 0.0 tail
0.1 4.0 /usr/libexec/mysqld

希望能够解决问题

点击登录