#!/bin/bash
#CPU监控
CPULoad(){
cpu_idle=`top -b -n 1 | grep Cpu | awk '{print $4}' | cut -f 2 -d "," | awk -F% '{print $1}' | cut -f 1 -d "."`
if [ $cpu_idle -lt 20 ]
then
echo "CPU负载过高,请处理,当前剩余$cpu_idle%" >> /home/log
sign=0
else
echo "ok"
sign=1
fi
}
#内存监控
MemLoad(){
mem_used=`free -m | grep Mem | awk '{print $3}'`
mem_total=`free -m | grep Mem | awk '{print $2'`
mem_per=`echo "scale=2;$mem_used/$mem_total*100" | bc | cut -f 1 -d "."`
if [ $mem_per -gt 70 ]
then
echo "mem占用超过预警值,达到$mem_per,请处理" >> /home/log
sign=0
else
echo "ok"
sign=1
fi
}
#硬盘监控
DiskLoad(){
disk_per=`df -h | awk NR==2 | awk '{print $5}' | awk -F% '{print $1}'`
if [ $disk_per -gt 85 ]
then
echo "根分区占用$disk_per%,超过预警值,请处理" >> /home/log
sign=0
else
echo "ok"
sign=1
fi
}
#短信通知
for n in CPULoad MemLoad DiskLoad
do
$n
if [ $sign -eq 0 ]
then
echo "send message..."
else
echo "nothing"
fi
done
阅读(1179) | 评论(0) | 转发(0) |