1、监控CPU利用率(通过vmstat工具)

#!/bin/bash
if [ `uname` != "Linux" ];then
echo "check os not linux."
exit
fi
which vmstat &>/dev/null
if [ $? -ne ];then
echo "vmstat command no found, please install procps package."
exit
fi
##################################################
cpu_us=`vmstat | awk '{print $13}' | sed -n '$p'`
cpu_sy=`vmstat | awk '{print $14}' | sed -n '$p'`
cpu_id=`vmstat | awk '{print $15}' | sed -n '$p'`
cpu_wa=`vmstat | awk '{print $16}' | sed -n '$p'` #等待I/0完成
cpu_sum=$(($cpu_us+$cpu_sy))
cpu_info()
{
echo "CPU_Sum : $cpu_sum% ( CPU_Use:${cpu_us}% , CPU_System:${cpu_sy}% )"
echo "CPU_Idle : ${cpu_id}%"
echo "CPU_Wait : ${cpu_wa}"
}
#cpu_info;
if [ $cpu_sum -ge ];then
echo "CPU utilization $cpu_sum." | mail -s "CPU Monitor" baojingtongzhi@.com
fi

2、监控内存利用率

#!/bin/bash
which bc &>/dev/null
if [ $? -ne ];then
echo "bc command no found, Please install bc package."
exit
fi
Date=`date +%F" "%H:%M`
IP=`ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -d: -f2`
Total=`free -m | grep Mem | awk '{print $2}'`
Use=`free -m | awk '/buffers\// {print $NF}'`
Free=$(($Total-$Use))
Total_conv=`echo "scale=2;$Total/1024" | bc | awk '{print $1"G"}'` #通过bc计算,保留小数点后两位(scale)
if [ $Free -lt ];then
Content=`echo -e "Date : $Date \nHost : $IP \nTotal : ${Total_conv} \nUse : ${Use}M \nFree : ${Free}M"`
echo "$Content" | mail -s "Memory Monitor" baojingtongzhi@.com
fi

3、监控磁盘利用率

#!/bin/bash
Date=`date +%F" "%H:%M`
IP=`ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -d: -f2`
Total=`fdisk -l | grep "Disk /dev/sd[a-z]" |awk '{print $2$3"GB"}' |sed 's/:/=/' |xargs echo -n |sed 's/[ ]/,/g'` #去掉换行符,并以逗号分隔在邮件显示总每个分区大小
Disk_Use=`df -h |awk '{print $1"="$5}' | sed '1d' | sed 's/%//g'`
for i in $Disk_Use
do
A=`echo $i |awk -F'=' '{print $2}'`
if [ $A -gt ];then
echo -e "Date : $Date \nHost : $IP \nTotal : $Total \nProblem : Part Use ${i}%" | mail -s "Disk Mo
nitor" baojingtongzhi@163.com
fi
done

 
 

Shell脚本监控CPU、内存和硬盘利用率的更多相关文章

  1. shell脚本监控cpu/内存使用率 转

    该脚本检测cpu和内存的使用情况,只需要调整memorySetting.cpuSetting.userEmail要发邮件报警的email地址即可 如果没有配置发邮件参数的哥们,已配置了的,直接飞到代码 ...

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

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

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

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

  4. grafana+influxdb+telegraf监控服务器cpu,内存和硬盘

    随便抄了一篇,目前我们的项目也在用,这个是linux和windows通吃的一种监控方案,非常有效,详细和优美,需要监控什么具体的业务内容,自己向influxdb中插入就行了. 监控服务器状态是运维必不 ...

  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. Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间

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

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

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

随机推荐

  1. SpringBoot与JPA

    JPA是什么 JPA是Java Persistence API的简称,中文名Java持久层API,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. JPA ...

  2. mac版 sublime快捷键大全

    按这几大类分类:文件 编辑 选择 查找 视图 去往 工具 项目 窗口 帮组一.文件cmd + N 新建文件cmd + S 保存文件cmd + shift + S 文件另存为cmd + alt + S ...

  3. (重点)Python深入之Python内存管理机制你会吗?

    前言本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.作者:醍醐三叶 请注意:如果你平时学Python遇到问题找不到人解答?或者没有 ...

  4. unity3d WeelCollider 漂移

    物理漂移 基础控制不在说明 Forward Friction 为轮胎直线摩擦力 Sideways Friction 为侧面摩擦力 Extremum Slip为速度达到多少后产生漂移效果 Extremu ...

  5. VS2013 MFC 库冲突引起的错误解决

    http://www.cnblogs.com/rainbowzc/archive/2010/06/29/1767248.html 7 1>LIBCMT.lib(crt0dat.obj) : er ...

  6. 谈一谈AOP面向切面编程

    AOP是什么 : AOP面向切面编程他是一种编程思想,是指在程序运行期间,将某段代码动态的切入到指定方法的指定位置,将这种编程方式称为面向切面编程 AOP使用场景 : 日志 事务 使用AOP的好处是: ...

  7. 写入Apache Hudi数据集

    这一节我们将介绍使用DeltaStreamer工具从外部源甚至其他Hudi数据集摄取新更改的方法, 以及通过使用Hudi数据源的upserts加快大型Spark作业的方法. 对于此类数据集,我们可以使 ...

  8. 04Shell流程控制

    流程控制 if 单分支结构 if 条件测试 then 命令序列 fi 双分支结构 if 条件测试 then 命令序列 else 命令序列 fi 多分支结构 if 条件测试 1 then 命令序列 [e ...

  9. Brett Beauregard大神的Arduino PID算法

    大神的全部PID http://brettbeauregard.com/blog/category/pid/ Improving the Beginner’s PID – Introduction I ...

  10. hdu 2955 Robberies (01背包好题)

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...