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或者FireFox浏览器观看. 图例: 代码: <!DOCTYPE html> <html lang="utf-8"> ...
- Awk使用及站点日志分析
Awk使用及站点日志分析 Awk简单介绍 概述 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入, ...
- I/O Mutiplexing poll 和 epoll
上一篇介绍了select的基本用法,接着来学习一下poll和epoll的基本用法.首先来看poll: #include <sys/poll.h> int poll (struct poll ...
- LintCode: Search A 2d Matrix
1. 设查找的数位y,第一行最后一列的数位x 如果x<y,x是第一行最大的,所以第一行都小于y,删除第一行: 如果x>y,x是最后一列最小的,所以最后一列都大于y,删除最后一列: 这样保证 ...
- 【SCM】关于Gradle与maven的几篇文章
Gradle官方文档:https://docs.gradle.org/current/userguide/installation.html#sec:download 使用 Gradle 命令行:ht ...
- Django模板过滤器详解
Django 模板过滤器也是我们在以后基于 Django 网站开发过程中会经常遇到的,如显示格式的转换.判断处理等.以下是 Django 过滤器列表,希望对为大家的开发带来一些方便. 一.形式:小写 ...
- javascript constrator and prototype
揭开js之constructor属性的神秘面纱 在js里面当new了一个对象时,这中间发生了什么? MDN - new运算符 当代码 new foo(...) 执行时: 一个新对象被创建.它继承自fo ...
- python 爬虫 爬取序列博客文章列表
python中写个爬虫真是太简单了 import urllib.request from pyquery import PyQuery as PQ # 根据URL获取内容并解码为UTF-8 def g ...
- 阅读《Android 从入门到精通》(9)——多项选择
多项选择(CheckBox) CheckBox 类是 Button 的子类,层次关系例如以下: android.widget.Button android.widget.CompoundButton ...
- 删除sql server用户时报15138错误
问题 在删除sql server中某数据库下的用户时报15138错误,见下图 解决 可用下述sql代码检查该用户的架构信息,然后逐一修正 SELECT s.name FROM sys.schemas ...