shell脚本监控cpu/内存使用率 转
该脚本检测cpu和内存的使用情况,只需要调整memorySetting、cpuSetting、userEmail要发邮件报警的email地址即可 #/bin/sh #auth yangxingyi 2017-12-12 17:50 #email [email?protected]126.com #this script check cpu used rate and memory used rate userEmail="[email?protected] [email?protected]" webIp="www101.200.***.***" memorySetting="80" cpuSetting="80" #check memory used rate totalMemory=$(free -m|awk ‘{print $2}‘|sed -n ‘2p‘) usedMemory=$(free -m|awk ‘{print $3}‘|sed -n ‘3p‘) freeMemory=$(free -m|awk ‘{print $4}‘|sed -n ‘3p‘) usedPerMemory=$(awk ‘BEGIN{printf "%.0f",(‘$usedMemory‘/‘$totalMemory‘)*100}‘) freePerMemory=$(awk ‘BEGIN{printf "%.0f",(‘$freeMemory‘/‘$totalMemory‘)*100}‘) if [ $usedPerMemory -ge $memorySetting ] then minfo="totalMemory:$totalMemory MB,used:$usedMemory MB,free:$freeMemory MB,usedPercent:$usedPerMemory%,freePrecent:$freePerMemory%" echo "$(date) $minfo used memory was gt $memorySetting% !" >> /sh/log_hard_disk_check echo " $minfo {$webIp}!" | mail -s "{$webIp} used memory was high!" $userEmail fi #check cpu used rate cpuUsed=$(top -n 1 | awk -F ‘[ %]+‘ ‘NR==3 {print $2}‘|awk -F ‘.‘ ‘{print $1}‘) if [ $cpuUsed -gt $cpuSetting ] then echo "$(date) cpu used $cpuUsed% " echo "$(date) cpu used $cpuUsed%"|mail -s "$webIp cpu used $cpuUsed%" $userEmail fi ? 原文:https://blog.csdn.net/qq_27517377/article/details/78784473 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |