shell脚本---------监控内存,超过警戒值发邮件告警

项目需求:

用shell写一个内存监控脚本,使用超过80%并发邮件告警

步骤分析:

free -m 			##内存使用情况

显示结果:

/ total used free shared buff/cache available
Mem: 3770 219 3170 3170 381 3325
Swap: 2047 0 2047

注释:

  • Mem:内存的使用情况总览表。
  • total:机器总的物理内存单位为:M
  • used:用掉的内存。
  • free:空闲的物理内存。

算取百分比:

  • 内存使用率=100*used/tol

比对做出判断

  • 判断内存使用率是否超过警戒值。

脚本实现:

#!/bin/bash
used=`free -m| grep "^Mem" | awk '{print $3}'`				#筛选出used的值
tol=`free -m| grep "^Mem" | awk '{print $2}'`					#筛选出total的值
let a=100*used/tol
echo $a
[ $a -ge 80 ] && /opt/sendEmail.sh [email protected] "内存警告" "内存使用率为$a%,请尽快处理"

sendEmail.sh

猜你喜欢

转载自blog.csdn.net/weixin_48190875/article/details/108304871