nagios 监控xenserver memery
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nagios 监控xenserver 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的主要内容,如果未能解决你的问题,请参考以下文章