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 ...
随机推荐
- ubuntu12.04 lts 安装gcc 4.8
gcc 4.8.1 是第一个完全支持C++11 的编译器,Windows上可以安装mingw版的,在sourceforge 上有下载,安装也比较方便.在Linux上安装的话需要首先安装一些依赖库.在U ...
- Swift语言精要 - 浅谈结构体(Struct)
CGRect, CGSize, CGPoint这些是 . String, Int, Array, Dictionary这些我们经常用的也是结构体(Struct). 那么结构体(Struct)到底是什么 ...
- 微软BI 之SSRS 系列 - 如何实现报表标签的本地化 - 中文和英文的互换
SSRS 中并没有直接提供本地化的配置方式,因此在 SSRS 中实现本地化,比如有英文标题还有可选的中文标题,就需要通过其它的方式来解决. 比如默认是这样的英文标题 - 但是本地中方用户可能比较喜欢看 ...
- Hibernate的配置中,c3p0连接池相关配置
一.配置c3p0 1.导入 hibernate-c3po连接池包,Maven地址是:http://mvnrepository.com/artifact/org.hibernate/hibernate- ...
- ubuntu中apache2的安装与卸载
一.装apache2 安装命令:sudo apt-get install apache2 启动/停止/重启apache2: service apache2 start/stop/restart 二. ...
- Hadoop: Add third-party libraries to MapReduce job
来自:http://hadoopi.wordpress.com/2014/06/05/hadoop-add-third-party-libraries-to-mapreduce-job/ Anybod ...
- Hive Web Interface的安装
Hive Web Interface,简称hwi,是Hive的Web接口. 首先,安装ant,下载ant,解压,并在/etc/profile中设置: export ANT_HOME=/opt/apac ...
- editcap的使用
editcap.exe -h Editcap (Wireshark) (v2.-gf42a0d2b6c) Edit and/or translate the format of capture fil ...
- js 数组 转为树形结构
题目: source = [{ id: 1, pid: 0, name: 'body' }, { id: 2, pid: 1, name: 'title' }, { id: 3, pid: 2, na ...
- 〖Android〗依据资源信息,Mock Android资源
#!/bin/bash - #=============================================================================== # # F ...