cat check_xen_cpu.sh #!/bin/sh function usage() { msg="$0 : use to check xenserver cpu 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-cpu-list | grep uuid | awk '{print $5}'` i=1 for uuid in $uuid_list do cpu_usage[$i]=`xe host-cpu-param-get param-name=utilisation uuid=$uuid` let i=i+1 done cpu_total=`echo ${cpu_usage[@]} | awk '{for(i=0;i<NF;i++) total+=$i; print total}'` cpu_avg=`echo ${cpu_usage[@]} | awk '{for(i=0;i<NF;i++) total+=$i;print total/NF}'` cpu_num=${#cpu_usage[@]} performance="$cpu_num cpus;total:$cpu_total;avg:$cpu_avg | cpu_total=$cpu_total;$warning;$critical;0;$cpu_num;cpu_avg=$cpu_avg;;;0;100;" function cmp_data(){ if [ $1 \< $2 ];then echo "OK $performance" exit_code=$STATE_OK elif [ $1 \> $3 ];then echo "CRITICSL $performance" exit_code=$STATE_CRITICAL else echo "WARNING $performance" exit_code=$STATE_WARNING fi } cmp_data $cpu_avg $warning $critical exit $exit_code
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。