# 内存使用率
mem_total=`mcsadmin getSystemMemory | awk '{print $2}' | sed -n '$p'`
mem_usage=`mcsadmin getSystemMemory | awk '{print $3}' | sed -n '$p'`
usage_int=`expr $mem_usage \* 100 / $mem_total`;
if [ 90 -lt $usage_int ]; then
function SendMessageToDingding(){
url="https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
UA="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24"
res=`curl -XPOST -s -L -H "Content-Type:application/json" -H "charset:utf-8" $url -d "
{
\"msgtype\": \"text\",
\"text\": {
\"content\": \"$1\n$2\n$3\"
}
}"`
echo $res
}
subject="xxx.xxx.xxx.xxx"
boy="MemUsage大于90%"
mem_total=`mcsadmin getSystemMemory | awk '{print $2}' | sed -n '$p'`
mem_usage=`mcsadmin getSystemMemory | awk '{print $3}' | sed -n '$p'`
usage_int=`expr $mem_usage \* 100 / $mem_total`;
usage_float=`echo "scale=2;$mem_usage * 100 / $mem_total" | bc`
SendMessageToDingding "Server:"$subject "警告:"$boy "Mem Usage:"$usage_float"%"
fi
脚本运行结果:
网友评论