Chinaunix首页 | 论坛 | 博客
  • 博客访问: 100603
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 322
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-27 13:38
文章分类

全部博文(26)

文章存档

2014年(4)

2013年(22)

我的朋友

分类: 系统运维

2013-03-30 18:16:48

#!/bin/bash
#from network
#This Nagios plugin can be checked your system memory status
USAGE_Method="$(basename $0) [-w|--warning] [-c|--critical]"
USAGE_Value="WARNING value must be large than CRITICAL value:`basename $0` $*"
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

#设置Nagios要求的状态
if [ $# -lt 4 ];then
echo
echo "Usage:$USAGE_Method"
echo
exit 0
fi

while [ $# -gt 0 ];do
case "$1" in
-w|--warning)
shift
WARNING=$1
;;
-c|--critical)
shift
CRITICAL=$1
;;
esac
shift
done

if [[ $WARNING -eq $CRITICAL || $WARNING -lt $CRITICAL ]]
then
echo
echo "$USAGE_Value"
echo
echo "Usage:$USAGE_Method"
echo
exit 0
fi

FREE_MEM=`free -m|grep -|awk -F' ' '{print $4}'`
TOTAL_MEM=`free -m|grep Mem|awk -F' ' '{print $2}'`
PERCENT=`bc<<<"scale=2;$FREE_MEM/$TOTAL_MEM"|tr '^.' ' '`

if [ $PERCENT -le $CRITICAL ];then
echo "CRITICAL - $FREE_MEM MB ($PERCENT%) Free Memory"
exit 2
fi
if [ $PERCENT -le $WARNING ];then
echo "WARNING - $FREE_MEM MB ($PERCENT%) Free Memory"
exit 1
fi
if [ $PERCENT -gt $WARNING ];then
echo "OK - $FREE_MEM MB ($PERCENT%) Free Memory"
exit 0
fi
阅读(1109) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~