1
|
<span style=
"color:rgb(0,0,0);font-family:'宋体', SimSun;"
>
#!/bin/bash<br>#====================================================<br># Author: lizhenliang - EMail:zhenliang369@163.com<br># Create Date: 2015-02-01<br># Description: cpu utilization monitor<br># blog:lizhenliang.blog.51cto.com<br>#====================================================<br>if [ `uname` != "Linux" ];then<br> echo "check os not linux."<br> exit 1<br>fi<br>which vmstat &>/dev/null<br>if [ $? -ne 0 ];then<br> echo "vmstat command no found, please install procps package." <br> exit 1<br>fi<br>##################################################<br>cpu_us=`vmstat | awk '{print $13}' | sed -n '$p'`<br>cpu_sy=`vmstat | awk '{print $14}' | sed -n '$p'`<br>cpu_id=`vmstat | awk '{print $15}' | sed -n '$p'`<br>cpu_wa=`vmstat | awk '{print $16}' | sed -n '$p'` #等待I/0完成<br>cpu_sum=$(($cpu_us+$cpu_sy))<br>cpu_info()<br>{<br>echo "CPU_Sum : $cpu_sum% ( CPU_Use:${cpu_us}% , CPU_System:${cpu_sy}% )" <br>echo "CPU_Idle : ${cpu_id}%"<br>echo "CPU_Wait : ${cpu_wa}"<br>}<br>#cpu_info;<br>if [ $cpu_sum -ge 90 ];then<br> echo "CPU utilization $cpu_sum." | mail -s "CPU Monitor" baojingtongzhi@163.com<br>fi<br></span>
|
1
|
<span style=
"color:rgb(0,0,0);font-family:'宋体', SimSun;"
>
#!/bin/bash<br>#====================================================<br># Author: lizhenliang - EMail:zhenliang369@163.com<br># Create Date: 2015-02-01<br># Description: memory utilization monitor<br># blog:lizhenliang.blog.51cto.com<br>#====================================================<br>which bc &>/dev/null<br>if [ $? -ne 0 ];then<br> echo "bc command no found, Please install bc package." <br> exit 1<br>fi<br>Date=`date +%F" "%H:%M`<br>IP=`ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -d: -f2`<br>Total=`free -m | grep Mem | awk '{print $2}'`<br>Use=`free -m | awk '/buffers\// {print $NF}'`<br>Free=$(($Total-$Use))<br>Total_conv=`echo "scale=2;$Total/1024" | bc | awk '{print $1"G"}'` #通过bc计算,保留小数点后两位(scale)<br>if [ $Free -lt 200 ];then<br> Content=`echo -e "Date : $Date \nHost : $IP \nTotal : ${Total_conv} \nUse : ${Use}M \nFree : ${Free}M"`<br> echo "$Content" | mail -s "Memory Monitor" baojingtongzhi@163.com<br>fi<br></span>
|
1
|
<span style=
"color:rgb(0,0,0);font-family:'宋体', SimSun;"
>
#!/bin/bash<br>#====================================================<br># Author: lizhenliang - EMail:zhenliang369@163.com<br># Create Date: 2015-02-01<br># Description: disk utilization monitor<br># blog:lizhenliang.blog.51cto.com<br>#====================================================<br>Date=`date +%F" "%H:%M`<br>IP=`ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -d: -f2`<br>Total=`fdisk -l | grep "Disk /dev/sd[a-z]" |awk '{print $2$3"GB"}' |sed 's/:/=/' |xargs echo -n |sed 's/[ ]/,/g'` #去掉换行符,并以逗号分隔在邮件显示总每个分区大小<br>Disk_Use=`df -h |awk '{print $1"="$5}' | sed '1d' | sed 's/%//g'`<br>for i in $Disk_Use<br>do<br> A=`echo $i |awk -F'=' '{print $2}'`<br> if [ $A -gt 8 ];then<br> echo -e "Date : $Date \nHost : $IP \nTotal : $Total \nProblem : Part Use ${i}%" | mail -s "Disk Mo<br>nitor" baojingtongzhi@163.com<br> fi<br>done<br></span>
|