您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。