linux服务器检测CPU使用率、负载以及java占用CPU使用率的shell脚本

#!/bin/bash

CPU=`top -b -n 1|grep Cpu|awk '{print $2}'|cut -f 1 -d "."`
LOAD=`top -b -n 1|grep load|awk '{print $12}'|cut -f 1 -d "."`
JAVA=`top -b -n 1|grep java|awk '{print $9}'|cut -f 1 -d "."`
echo "CPU:" $CPU"%"
echo "LOAD:" $LOAD
if [ $CPU -gt 50 ] ||[ $LOAD -gt 2 ]||[ $JAVA -gt 80 ]
then
SMS=`curl -d "params={"content":"admin.dbappwaf.cn ERROR!!! cpu is $CPU load is $LOAD java use cpu is $JAVA ","send":[{"to":"","addr":"18667935188"}]}" "http://host:8089/msgserver/message?type=1"`

fi
echo `date` "CPU IS "$CPU"% LOAD is" $LOAD "JAVA is " $JAVA "% SMS:"$SMS >> /home/log/cpu.log

原文地址:https://www.cnblogs.com/shijiaoyun/p/5806025.html