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

nagios 监控xenserver memery

时间:2017-01-25 23:24:03      阅读:399      评论:0      收藏:0      [点我收藏+]

标签:nagios xen memery

cat check_xen_mem.sh
#!/bin/sh


function usage()
{
        msg="$0 : use to check xenserver memery usage for nagios"
        echo "****************************************************"
        echo -e "\033[1;94m${msg}\033[0m"
        echo -e "Usage:"
        echo -e "       $0 [-w warning -c critical]"
        echo -e "       $0 -w 80 -c 90 "
        echo "****************************************************"
}

if [ $# -eq 0 ];then
        warning=0.85
        critical=0.95
elif [ "$1" = "-w" ];then
        warning=`echo $2`
        shift
        shift
        if [ "$1" != "-c" ];then
                usage
                exit 1
        fi
        critical=`echo $2`
        shift
        shift
else
	usage 
	exit 1
fi

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3


uuid_list=`xe host-list | grep uuid | awk ‘{print $5}‘`
i=1
for uuid in $uuid_list
do
	each_mem_total[$i]=`xe host-param-get param-name=memory-total uuid=$uuid`
	each_mem_free[$i]=`xe host-param-get param-name=memory-free uuid=$uuid`
	let i=i+1
done

mem_total=`echo ${each_mem_total[@]} | awk ‘{for(i=0;i<NF;i++) total+=$i; print total/1024/1024/1024}‘`
mem_free=`echo ${each_mem_free[@]} | awk ‘{for(i=0;i<NF;i++) free+=$i;print free/1024/1024/1024}‘`
#mem_usage=$(((mem_total-mem_free)/mem_total))
mem_usage=`awk -v a=$mem_total -v b=$mem_free ‘BEGIN{printf "%.2f",(a-b)/a }‘`
host_num=${#each_mem_total[@]}

performance="$host_num host; usage: $mem_usage; free: $mem_free | mem_usage=$mem_usage;$warning;$critical;0;100;mem_free=$mem_free;;;;;"

function cmp_data(){
	if [ $1 \< $2 ];then
		echo "OK $performance"
		exit_code=$STATE_OK
	elif [ $1 \> $3 ];then
		echo "CRITICAL $performance"
		exit_code=$STATE_CRITICAL
	else
		echo "WARNING $performance"
		exit_code=$STATE_WARNING
	fi
}

cmp_data $mem_usage $warning $critical
exit $exit_code


本文出自 “月童” 博客,谢绝转载!

nagios 监控xenserver memery

标签:nagios xen memery

原文地址:http://littlefive.blog.51cto.com/6440205/1894182

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