shell脚本监控系统中占用CPU,内存最大的进程

#!/bin/bash
#Monitor System Cpu and Memory Status
#Modify:20180817
#Log File
#Get top 10 Cpu Usage
[ -f /tmp/mon_cpu_mem_usage.log ] || touch /tmp/mon_cpu_mem_usage.log
log=/tmp/mon_cpu_mem_usage.log


process=`ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head|sed -n '1p'|awk '{print $11}'`
process_name=$(echo $process| awk '{print $NF}')



cpu_stat=`ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head|sed -n '1p'|awk '{print $3}'`
cpu_load=$(echo $cpu_stat| awk '{print $NF}')


mem_stat=`ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head|sed -n '1p'|awk '{print $4}'`
mem_load=$(echo $mem_stat| awk '{print $NF}')


if [ `expr $cpu_load \> 90.0` -eq  1 ];then


        echo "`date` Cpu Load Error,Please Contact Administrator  [Process Name]:$process_name [Max Load Value is]:$cpu_load"|tee -a  $log
else
        echo "`date` Cpu Load OK, [Process Name]:$process_name [Max Load Value is]:$cpu_load "|tee -a $log
fi


if [ `expr $mem_load \> 90.0` -eq  1 ];then


        echo "`date` Memory Load Error, [Process Name]:$process_name [Max Load Value is]:$mem_load Please Contact Administrator"|tee -a $log
else
        echo "`date` Memory Load OK, [Process Name]:$process_name [Max Load Value is]:$mem_load"|tee -a  $log
fi


echo "Log file:$log"
分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS