#!/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) |