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 $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
网站名称:nagios监控xenservercpu资源
本文路径:
http://kswsj.cn/article/igigpj.html