多cpu 情况下,对每个cpu使用情况的监控脚本
时间:2015-01-17 17:35来源:linux.it.net.cn 作者:IT
-
!/bin/sh
-
-
DATE=`date +%Y%m%d%H`
-
DIR="/root/"
-
MAILX=/usr/bin/mailx
-
NOTIFY="174915592@qq.com"
-
FROM="*****@****.com"
-
-
cd $DIR
-
rm out.`date -d -1day +%Y%m%d`*
-
rm out.$DATE
-
rm report_cpu
-
-
awk '$0 ~/cpu/' /proc/stat | while read line
-
do
-
echo "$line" | awk '{total=$2+$3+$4+$5+$6+$7+$8;free=$5; print$1" Free "free/total*100"%", "Used " (total-free)/total*100"%"}'>>out.$DATE
-
-
done
-
-
while read line
-
do
-
cpu_usage=`echo $line | awk '{print $5}' |sed 's/\%$//g'`
-
#cpu_usage=`echo $line | awk '{print $5}'`
-
echo $cpu_usage
-
flag=`expr $cpu_usage \> 0.4`
-
-
if [ "$flag" == "1" ] ; then
-
cpu=`echo $line|awk '{print $1}'`
-
usage=`echo $line|awk '{print $5}'`
-
echo "the $cpu used $usage">>report_cpu
-
-
fi
-
done <out.$DATE
-
-
echo "please check below processes :" >>report_cpu
-
ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head >>report_cpu
-
-
-
-
$MAILX -s "the cpu of $hostname used too much , please check it" $NOTIFY<report_cpu
(责任编辑:IT) |
------分隔线----------------------------