该脚本检测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. 【Python】使用geopy由经纬度找地理信息

    from geopy.geocoders import Nominatim geolocator = Nominatim() location = geolocator.reverse("3 ...

  2. (纪录片)你必须知道的科学 The Science That You Have To Know (2014)

    简介: 类型: 纪录片制片国家/地区: 英国语言: 英语上映日期: 2014-2片长: 150分钟 主要内容: 你有没有认真想过,自己的身体有多奇妙?人体是世间最复杂的一项工程杰作,他也带来了一些非常 ...

  3. Android 为何比 iOS 卡?【转载】

    Android 卡是必须的,当你的手机装了 20 多个 app,那不卡才叫见鬼了呢,我手机微信都打不开,手机直接自动重启啦~哪种东西生来就是完美的呢?即便是台式机,也是越用越慢.换句话,如果没有特别原 ...

  4. android中实现简单的聊天功能

    这个例子只是简单的实现了单机版的聊天功能,自己跟自己聊,啦啦~~ 主要还是展示RecyclerView控件的使用吧~ 参考我之前写的文章: android中RecyclerView控件的使用 andr ...

  5. jQuery页面滚动图片等元素动态加载实现

    一.关于滚动显屏加载 常常会有这样子的页面,内容很丰富,页面很长,图片较多.比如说光棍节很疯狂的淘宝商城页面. 或者是前段时间写血本买了个高档耳机的京东商城页面,或者是新浪微博之类. 这些页面图片数量 ...

  6. LintCode: Single Number

    C++ (1)异或操作 3^3=0 (2)for (auto &i : Obejuct) {} class Solution { public: /** * @param A: Array o ...

  7. HDOJ 5288 OO’s Sequence 水

    预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 13 ...

  8. Java并发容器——CopyOnWriteArrayList

    CopyOnWriteArrayList是“读写分离”的容器,在写的时候是先将底层源数组复制到新数组中,然后在新数组中写,写完后更新源数组.而读只是在源数组上读.也就是,读和写是分离的.由于,写的时候 ...

  9. edit-distance-动态规划,计算两词之间变换的最小步数

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  10. vs2017莫名自动退出调试状态可以尝试一下如下的方法