该脚本检测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/内存使用率 转的更多相关文章

  1. linux实现shell脚本监控磁盘内存达到阈值时清理catalina.out日志

    想在服务器上写一个shell脚本,在磁盘使用率达到80%时,自动清理掉一些没有用的日志文件,根据这个想法,在生产环境上写了一个以下脚本,按照该流程,可实现在linux环境做一个定时任务来执行shell ...

  2. Shell脚本监控CPU、内存和硬盘利用率

    1.监控CPU利用率(通过vmstat工具) #!/bin/bash #==================================================== # Author: l ...

  3. shell脚本监控Linux系统性能指标

    2016-11-04 22:41 原作者不详 分类: Linux(7) 在服务器运维过程中,经常需要对服务器的各种资源进行监控, 例如:CPU的负载监控,磁盘的使用率监控,进程数目监控等等,以在系统出 ...

  4. Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间

    Linux简单Shell脚本监控MySQL.Apache Web和磁盘空间 1. 目的或任务 当MySQL数据库.Apache Web服务器停止运行时,重新启动运行,并发送邮件通知: 当服务器磁盘的空 ...

  5. 用shell脚本监控进程是否存在 不存在则启动的实例

    用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ]th ...

  6. shell脚本监控网站状态

    shell脚本监控网站状态 #!/bin/sh date=`date +"%Y%m%d-%H%M"` title="status" contentFail=&q ...

  7. linux shell脚本监控进程是否存在

    用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货:    #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ...

  8. shell脚本监控系统负载、CPU和内存使用情况

    hostname >>/home/vmuser/xunjian/xj.logdf -lh >>/home/vmuser/xunjian/xj.logtop -b -n 1 | ...

  9. Shell之监控cpu、内存、磁盘脚本

    #!/bin/bash #获取内存情况 mem_total=`free | awk 'NR==2{print $2}'` #获取内存总大小 mem_use=`free | awk 'NR==2{pri ...

随机推荐

  1. 我的webrequest经验

    1 webrequest 是什么:编程方式模拟web请求,利用webrequest可以实现 相当于一个浏览器请求一个网页的效果,但是它始终是模拟请求, 与浏览器输入框输入网址请求不一样. 2 程序设计 ...

  2. VMware vCenter Orchestrator

    使用范例: VMware Automation with vCenter Orchestrator http://www.rodmach.com/blog/?p=46 直接从 VSPHERE CLIE ...

  3. 012-Go ORM框架之Gorm测试

    1:参考:https://github.com/jinzhu/gorm 2:数据库脚本(pg) -- create table posts( id serial primary key, conten ...

  4. mySQL内存及虚拟内存优化设置[转]

    mySQL内存及虚拟内存优化设置 . 数据库mySQL内存优化G-LB  为了装mysql环境测试,装上后发现启动后mysql占用了很大的虚拟内存,达8百多兆.网上搜索了一下,得到高人指点my.ini ...

  5. win7下安装matlab后打开出错“error starting desktop”的解决办法

    在matlab快捷图标上右键,选择"还原以前的版本"--"兼容性"选项卡,在"以兼容模式运行这个程序"前面打勾,并选择"windo ...

  6. hibernate 02之helloworld

    1.安装插件 安装方法说明(hibernatetools-.Final): Help --> Install New Software... Click Add... In dialog Add ...

  7. 单目视觉里程计 mono vo

    之前为了修改svo进行了一些不同的尝试,两个视频demo在以下. 效果1 视频链接: https://v.qq.com/x/page/d0383rpx3ap.html 在不同数据集上測试 效果2 视频 ...

  8. 【Linux】常见Linux默认的shell

    常见的操作系统下的shell: Linux下默认的shell是Bourne Again shell(bash) Solaris和FreeBSD下默认的是Bourne shell(sh) AIX系统下默 ...

  9. GitLab概念——Group、Project、Member

    概念说明: Group是一个父子结构的目录 Group每一级都可以设置关联的Member,同时每一级下都可以创建项目 Group关联的Member和Member对应的权限,会继承到Group下的所有P ...

  10. 最长公共子序列(POJ1458)

    题目链接:http://poj.org/problem?id=1458 题目大意:给出两个字符串,求出这样的一个最长的公共子序列的长度:子序列中的每个字符都能在两个原串中找到,而且每个字符的先后顺序和 ...