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

栏目: 服务器 · 发布时间: 6年前

#!/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"

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


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Programming Python

Programming Python

Mark Lutz / O'Reilly Media / 2006-8-30 / USD 59.99

Already the industry standard for Python users, "Programming Python" from O'Reilly just got even better. This third edition has been updated to reflect current best practices and the abundance of chan......一起来看看 《Programming Python》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具