您好,登錄后才能下訂單哦!
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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。