Linux之监控服务器内存、CPU、磁盘使用率shell脚本

前端之家收集整理的这篇文章主要介绍了Linux之监控服务器内存、CPU、磁盘使用率shell脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

监控服务器内存、cpu、磁盘使用率脚本内容(包含邮件告警):

@H_502_3@#Memory totalMemory=$(free -m | awk -F '[ :]+' NR==2{print $2}') usedMemory=$(free -m | awk -F NR==2{print $3}) freeMemory=$(free -m|awk {print $4}'|sed -n 3p) usedPerMemory=$(awk BEGIN{printf "%.0f",('$usedMemory/'$totalMemory)*100}) freePerMemory=$(awk '$freeMemory) logFile=/tmp/monitor.log #alerm date now_time=`date +%Y-%m%d %H:%M:%S` #Disk diskusAge=$(df -h | grep /dev/mapper/centos-root | awk -F [ %]+{print $5}) #cpu cpuusAge=$(top -b -n 1 |grep cpu|awk {print $8}'|cut -f 1 -d.) echo $cpuusAge # send mail function send_mail(){ mail -s "test alerm" test@163.com < /tmp/monitor.log } if [[ $usedPerMemory" > 90 ]] || [[ $diskusAge$cpuusAge95 ]];then echo 报警时间:${now_time}" > $logFile echo cpu usage:${cpuusAge}%" >>Memory usage:${usedPerMemory}%Disk usage:${diskusAge}% $logFile send_mail fi

 

猜你在找的Linux相关文章