码迷,mamicode.com
首页 > 移动开发 > 详细

nagios监控主机内存使用情况

时间:2015-08-10 22:32:29      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

#!/bin/bash
STAT_OK=0
STAT_WARNING=1
STAT_CRITICAL=2
STAT_UNKNOWN=3
total_mem=`free -m |awk ‘NR==2{print $2}‘`
used_mem=`free -m |awk ‘NR==3{print $3}‘` 
free_mem=$[$total_mem - $used_mem]
use_percent=`echo $total_mem $used_mem|awk ‘{print ($2 / $1)*100}‘`
use_per=`echo $use_percent|awk ‘{print int($1)}‘`
help() {
        echo "USAGE:`basename $0` [-w] <used percent> [-c] <used percent> [-h]"
        exit -1
}
warning=80
critical=90
while getopts "w:c:h" opt
do
        case $opt in
                w)      warning=$OPTARG
                        ;;
                c)      critical=$OPTARG
                        ;;
                h)      help
                        ;;
                *)      unkown=$OPTARG
                        echo "error,plase check for help,USAGE:./`basename $0` -h"
                        exit $STAT_UNKNOWN
                        ;;
        esac
done
if [ $use_per -lt $warning ];then
        echo "OK - total:$total_mem MB,used:$used_mem MB,free:$free_mem MB | total_mem=$total_mem used_mem=$used_mem free_mem=$free_mem"
        exit $STAT_OK
elif [ $use_per -ge $warning ] && [ $use_per -lt $critical ]
then
                 echo "WARNING - total:$total_mem MB,used:$used_mem MB,free:$free_mem MB | total_mem=$total_mem used_mem=$used_mem free_mem=$free_mem"
                 exit $STAT_WARNING
else
                 echo "CRITICAL - total:$total_mem MB,used:$used_mem MB,free:$free_mem MB | total_mem=$total_mem used_mem=$used_mem free_mem=$free_mem"
                 exit $STAT_CRITICAL
        
fi

nagios监控主机内存使用情况

标签:

原文地址:http://my.oschina.net/u/1011578/blog/490342

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!