shell脚本监控cpu/内存使用率
2017-12-12 17:56
706 查看
该脚本检测cpu和内存的使用情况,只需要调整memorySetting、cpuSetting、userEmail要发邮件报警的email地址即可
如果没有配置发邮件参数的哥们,已配置了的,直接飞到代码区:
1.vim /etc/mail.rc
2.找到以下内容
set from=yangxingyi@duoduofenqi.com #来自什么
set smtp=smtp.exmail.qq.com #根据您的邮箱发件服务器填写,我这位是TX的企业邮箱
set smtp-auth-user=yangxingyi@duoduofenqi.com #邮箱用户名
set smtp-auth-password=您的密码 #注意是发邮件密码,有的邮箱服务商登陆密码和发件密码不一样的哦
set smtp-auth=login
**配置完成后可以直接echo ‘test content’ |mail -s ‘test title’ yangxingyi@duoduofenqi.com
如果收到邮件,说明您邮件配置是ok的,否则就是有见没配置好哦,重新检查用户名密码,smtp有没有填错!!!**
如果您觉得有用的话直接搬走就行了,不用联系我!!!
如果没有配置发邮件参数的哥们,已配置了的,直接飞到代码区:
1.vim /etc/mail.rc
2.找到以下内容
set from=yangxingyi@duoduofenqi.com #来自什么
set smtp=smtp.exmail.qq.com #根据您的邮箱发件服务器填写,我这位是TX的企业邮箱
set smtp-auth-user=yangxingyi@duoduofenqi.com #邮箱用户名
set smtp-auth-password=您的密码 #注意是发邮件密码,有的邮箱服务商登陆密码和发件密码不一样的哦
set smtp-auth=login
**配置完成后可以直接echo ‘test content’ |mail -s ‘test title’ yangxingyi@duoduofenqi.com
如果收到邮件,说明您邮件配置是ok的,否则就是有见没配置好哦,重新检查用户名密码,smtp有没有填错!!!**
如果您觉得有用的话直接搬走就行了,不用联系我!!!
#/bin/sh #auth yangxingyi 2017-12-12 17:50 #email openweixin666@126.com #this script check cpu used rate and memory used rate userEmail="269754243@qq.com openweixin666@126.com" 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
相关文章推荐
- Linux---服务器CPU 内存 磁盘 监控SHELL脚本
- 利用Shell脚本来监控Linux系统的负载、CPU、内存、硬盘、用户登录数
- 监控CPU、内存和硬盘利用率的shell脚本
- 使用shell脚本监控服务器内存和cpu使用量,自动清理无效内存(补充篇)
- 利用shell监控cpu、磁盘、内存使用率
- 利用shell脚本来监控linux系统的负载与CPU和内存使用情况
- shell脚本监控系统负载、CPU和内存使用情况
- shell脚本监控系统负载、CPU和内存使用情况
- linux系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- 如何用shell脚本监控服务器负载、cpu、内存、硬盘和登录用户数
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本 推荐
- shell脚本监控系统负载、CPU和内存使用情况
- Shell脚本监控Linux系统内存使用率
- 统计 CPU 内存 硬盘 使用率的shell脚本
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- 【找一找青春】Linux 性能监控之CPU&内存&IO监控Shell脚本1[转]
- shell脚本监控系统负载、CPU和内存使用情况
- shell脚本监控磁盘I/O,cpu,内存
- 一个用了统计CPU 内存 硬盘 使用率的shell脚本
- linux系统的负载与CPU、内存、硬盘、用户数监控shell脚本