shell脚本监控cpu/内存使用率 转
该脚本检测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有没有填错!!!**
如果您觉得有用的话直接搬走就行了,不用联系我!!!
#/bin/sh
#auth yangxingyi -- :
#email openweixin666@.com
#this script check cpu used rate and memory used rate
userEmail="269754243@qq.com openweixin666@126.com"
webIp="www101.200.***.***"
memorySetting=""
cpuSetting=""
#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 | 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
shell脚本监控cpu/内存使用率 转的更多相关文章
- linux实现shell脚本监控磁盘内存达到阈值时清理catalina.out日志
想在服务器上写一个shell脚本,在磁盘使用率达到80%时,自动清理掉一些没有用的日志文件,根据这个想法,在生产环境上写了一个以下脚本,按照该流程,可实现在linux环境做一个定时任务来执行shell ...
- Shell脚本监控CPU、内存和硬盘利用率
1.监控CPU利用率(通过vmstat工具) #!/bin/bash #==================================================== # Author: l ...
- shell脚本监控Linux系统性能指标
2016-11-04 22:41 原作者不详 分类: Linux(7) 在服务器运维过程中,经常需要对服务器的各种资源进行监控, 例如:CPU的负载监控,磁盘的使用率监控,进程数目监控等等,以在系统出 ...
- Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间
Linux简单Shell脚本监控MySQL.Apache Web和磁盘空间 1. 目的或任务 当MySQL数据库.Apache Web服务器停止运行时,重新启动运行,并发送邮件通知: 当服务器磁盘的空 ...
- 用shell脚本监控进程是否存在 不存在则启动的实例
用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ]th ...
- shell脚本监控网站状态
shell脚本监控网站状态 #!/bin/sh date=`date +"%Y%m%d-%H%M"` title="status" contentFail=&q ...
- linux shell脚本监控进程是否存在
用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ...
- shell脚本监控系统负载、CPU和内存使用情况
hostname >>/home/vmuser/xunjian/xj.logdf -lh >>/home/vmuser/xunjian/xj.logtop -b -n 1 | ...
- Shell之监控cpu、内存、磁盘脚本
#!/bin/bash #获取内存情况 mem_total=`free | awk 'NR==2{print $2}'` #获取内存总大小 mem_use=`free | awk 'NR==2{pri ...
随机推荐
- [Canvas]越来越近的女孩
本作比前作增加了控制功能,观看动态效果请点此下载代码用Chrome或Firfox浏览器观看. 图例: 代码: <!DOCTYPE html> <html lang="utf ...
- 树莓派中找不到/dev/video0的解决方案及RaspberryCam的使用
一.原因 当使用CSI连接的方式将摄像头模块连接树莓派后,在/dev/中找不到video0,因此使用一些第三方库(如Opencv或RaspberryCam)去调用摄像头时,无法调用成功. 二.解决方法 ...
- Linux安装pear包
一.安装pear包. 1.安装: $ sudo wget http://pear.php.net/go-pear.phar $ sudo php go-pear.har 2.查看pear下安装的包: ...
- Tomcat下HTTPS双向认证配置以及客户端调用案例
1:生成服务器端的keystore和truststore文件 (1)以jks格式生成服务器端包含Public key和Private Key的keystore文件 keytool -genkey -a ...
- javascript string replace 正则替换
利用正则式实现首字母大写,丧心病狂是不是?好好的substr不用. JavaScript replace() 方法 r = /^(.)(?=.*)/; str = 'abc'; var str2 = ...
- Statement、PreparedStatemnt、CallableStatement
第一.Statement(Statement代表一个特定的容器,来对一个特定的数据库执行语句) * 执行查询的方法 Statement=Connection.createStatement();//创 ...
- Page Visibility实现焦点丢失提醒
0.前言 HTML5 Page Visibility API是一个很实用的特性.当页面对用户不可见时,暂停播放页面中的视频.动画.声音.以及其它耗费内存的操作,等用户回来时.再继续这些操作. 当然,最 ...
- 单目视觉里程计 mono vo
之前为了修改svo进行了一些不同的尝试,两个视频demo在以下. 效果1 视频链接: https://v.qq.com/x/page/d0383rpx3ap.html 在不同数据集上測试 效果2 视频 ...
- django之创建第6-1个项目-自定义过滤器
1.在站点blog目录下创建templatetags文件夹 2.templatetags目录下需要作为一个包来处理和调用其中的内容,需要有一个__init__.py文件 3.在templatetags ...
- python 什么叫迭代
# -*- coding: cp936 -*- #xiaodeng #python 27 #什么叫迭代 #如果给定一个list/tuple,可以通过for循环遍历出来,这种遍历我们称之为迭代 #案例3 ...