監控系統資源加郵件提醒
阿新 • • 發佈:2018-01-10
等待 dev util 關於 roc man 磁盤 pri free #!/usr/bin/bash
echo "##########關於cpu##########"
vmstat &>/dev/null
if [ $? -ne 0 ];then
echo "vmstat command is not found,please install it!"
yum install -y procps
echo "命令已安裝!請重新執行該命令"
exit 0
fi
#us 用戶使用cpu花費時間; sy 系統使用cpu花費時間;id cpu空閑時間id=us+sy;wa cpu耗費等待io上時間
cpu_us=
cpu_sy=
cpu_id=
cpu_wa=
cpu_sum=$(($cpu_us+$cpu_sy))
echo "cpu空閑時間(id):$cpu_id"
echo "cpu等待時間:"$cpu_wa#!/usr/bin/bash
echo "##########關於cpu##########"
vmstat &>/dev/null
if [ $? -ne 0 ];then
echo "vmstat command is not found,please install it!"
yum install -y procps
echo "命令已安裝!請重新執行該命令"
exit 0
fi
#us 用戶使用cpu花費時間; sy 系統使用cpu花費時間;id cpu空閑時間id=us+sy;wa cpu耗費等待io上時間
cpu_us=
cpu_sy=
cpu_id=
cpu_wa=
cpu_sum=$(($cpu_us+$cpu_sy))
echo "cpu空閑時間(id):$cpu_id"
echo "cpu等待時間:"$cpu_wa
echo "cpu 總共用時(us+sy): $cpu_sum"
if [ $cpu_sum -ge 70 ];then
echo "your cpu utilization is $cpu_sum."|mail -s "cpu utilization" [email protected]
fi
echo "###########關於內存#############"
free &>/dev/null
if [ $? -ne 0 ];then
echo "free command is not found,please install it!"
exit 0
fi
memory=
echo $memory
memory_1=
if [ $? -ge 80 ];then
echo "your memory utilization is $memory_1"|mail -s "memory error" [email protected]
fi
echo "#############關於磁盤############"
df &>/dev/null
if [ $? -ne 0 ];then
echo "free command is not found,please install it!"
exit 0
fi
disk_0=
disk=
echo $disk_0
for i in $disk
do
if [ $i -ge 70 ];then
echo "your disk utilization is %i"|mail -s "disk error" [email protected]
fi
done
echo "cpu 總共用時(us+sy): $cpu_sum"
if [ $cpu_sum -ge 70 ];then
echo "your cpu utilization is $cpu_sum."|mail -s "cpu utilization" [email protected]
fi
echo "###########關於內存#############"
free &>/dev/null
if [ $? -ne 0 ];then
echo "free command is not found,please install it!"
exit 0
fi
memory=
echo $memory
memory_1=
if [ $? -ge 80 ];then
echo "your memory utilization is $memory_1"|mail -s "memory error" [email protected]
fi
echo "#############關於磁盤############"
df &>/dev/null
if [ $? -ne 0 ];then
echo "free command is not found,please install it!"
exit 0
fi
disk_0=
disk=
echo $disk_0
for i in $disk
do
if [ $i -ge 70 ];then
echo "your disk utilization is %i"|mail -s "disk error" [email protected]
fi
done
echo "##########關於cpu##########"
vmstat &>/dev/null
if [ $? -ne 0 ];then
echo "vmstat command is not found,please install it!"
yum install -y procps
echo "命令已安裝!請重新執行該命令"
exit 0
fi
#us 用戶使用cpu花費時間; sy 系統使用cpu花費時間;id cpu空閑時間id=us+sy;wa cpu耗費等待io上時間
cpu_us=
vmstat | awk ‘{print $13}‘ | sed -n ‘$p‘
cpu_sy=
vmstat | awk ‘{print $14}‘ | sed -n ‘$p‘
cpu_id=
vmstat | awk ‘{print $15}‘ | sed -n ‘$p‘
cpu_wa=
vmstat | awk ‘{print $16}‘ | sed -n ‘$p‘
cpu_sum=$(($cpu_us+$cpu_sy))
echo "cpu空閑時間(id):$cpu_id"
echo "cpu等待時間:"$cpu_wa#!/usr/bin/bash
echo "##########關於cpu##########"
vmstat &>/dev/null
echo "vmstat command is not found,please install it!"
yum install -y procps
echo "命令已安裝!請重新執行該命令"
exit 0
fi
#us 用戶使用cpu花費時間; sy 系統使用cpu花費時間;id cpu空閑時間id=us+sy;wa cpu耗費等待io上時間
cpu_us=
vmstat | awk ‘{print $13}‘ | sed -n ‘$p‘
cpu_sy=
vmstat | awk ‘{print $14}‘ | sed -n ‘$p‘
cpu_id=
vmstat | awk ‘{print $15}‘ | sed -n ‘$p‘
cpu_wa=
vmstat | awk ‘{print $16}‘ | sed -n ‘$p‘
cpu_sum=$(($cpu_us+$cpu_sy))
echo "cpu空閑時間(id):$cpu_id"
echo "cpu等待時間:"$cpu_wa
echo "cpu 總共用時(us+sy): $cpu_sum"
if [ $cpu_sum -ge 70 ];then
echo "your cpu utilization is $cpu_sum."|mail -s "cpu utilization" [email protected]
fi
echo "###########關於內存#############"
free &>/dev/null
if [ $? -ne 0 ];then
echo "free command is not found,please install it!"
exit 0
fi
memory=
free -m|grep Mem|awk ‘{print "使用的內存:"$2"M,還剩余內存"$3"M,所以內存使用率為:"$3/$2*100"%"}‘
echo $memory
memory_1=
free -m|grep Mem|awk ‘{print ""$3/$2*100""}‘
if [ $? -ge 80 ];then
echo "your memory utilization is $memory_1"|mail -s "memory error" [email protected]
fi
echo "#############關於磁盤############"
df &>/dev/null
if [ $? -ne 0 ];then
echo "free command is not found,please install it!"
exit 0
fi
disk_0=
df -h|sed -n ‘3,5p‘|awk ‘{print $(NF-1)}‘
disk=
df -h|sed -n ‘3,5p‘|awk ‘{print $(NF-1)}‘|cut -b 1
echo $disk_0
for i in $disk
do
if [ $i -ge 70 ];then
echo "your disk utilization is %i"|mail -s "disk error" [email protected]
fi
done
echo "cpu 總共用時(us+sy): $cpu_sum"
if [ $cpu_sum -ge 70 ];then
echo "your cpu utilization is $cpu_sum."|mail -s "cpu utilization" [email protected]
fi
echo "###########關於內存#############"
free &>/dev/null
if [ $? -ne 0 ];then
echo "free command is not found,please install it!"
exit 0
fi
memory=
free -m|grep Mem|awk ‘{print "使用的內存:"$2"M,還剩余內存"$3"M,所以內存使用率為:"$3/$2*100"%"}‘
echo $memory
memory_1=
free -m|grep Mem|awk ‘{print ""$3/$2*100""}‘
if [ $? -ge 80 ];then
echo "your memory utilization is $memory_1"|mail -s "memory error" [email protected]
fi
echo "#############關於磁盤############"
df &>/dev/null
if [ $? -ne 0 ];then
echo "free command is not found,please install it!"
exit 0
fi
disk_0=
df -h|sed -n ‘3,5p‘|awk ‘{print $(NF-1)}‘
disk=
df -h|sed -n ‘3,5p‘|awk ‘{print $(NF-1)}‘|cut -b 1
echo $disk_0
for i in $disk
do
if [ $i -ge 70 ];then
echo "your disk utilization is %i"|mail -s "disk error" [email protected]
fi
done
監控系統資源加郵件提醒