nagios插件监控cpu,可pnp画图
check_cpu 是依据从exchange.nagios.org 的脚本修改的。使用原始脚本结构,函数名称、参数也没怎么变化,有看到的,勿拍砖。
创新互联专业为企业提供伊美网站建设、伊美做网站、伊美网站设计、伊美网站制作等企业网站建设、网页设计与制作、伊美企业网站模板建站服务,十多年伊美做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
#!/bin/bash
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
PROGNAME=`basename $0`
warning=$2
critical=$4
process=$6
get_wcdiff() {
if [ ! -z "$warning" -a ! -z "$critical" ]
then
wclvls=1
if [ ${warning} -gt ${critical} ]
then
wcdiff=1
fi
elif [ ! -z "$warning" -a -z "$critical" ]
then
wcdiff=2
elif [ -z "$warning" -a ! -z "$critical" ]
then
wcdiff=3
fi
}
val_wcdiff() {
if [ "$wcdiff" = 1 ]
then
echo "Please adjust your warning/critical thresholds. The warning must be lower than the critical level!"
exit $ST_UK
elif [ "$wcdiff" = 2 ]
then
echo "Please also set a critical value when you want to use warning/critical thresholds!"
exit $ST_UK
elif [ "$wcdiff" = 3 ]
then
echo "Please also set a warning value when you want to use warning/critical thresholds!"
exit $ST_UK
fi
}
get_vals() {
tmp_output=$(top -n 1 -b | grep $process )
top_cpu=$(echo ${tmp_output} | awk '{print $9}')
int_cpu=$(echo ${top_cpu%.*})
}
do_perfdata() {
perfdata="cpu=${top_cpu}%"
}
get_wcdiff
val_wcdiff
get_vals
do_perfdata
if [ -n "$warning" -a -n "$critical" ]
then
if [ "$int_cpu" -ge "$warning" -a "$int_cpu" -lt "$critical" ]
then
echo "WARNING - ${perfdata} | ${perfdata}"
exit $ST_WR
elif [ "$int_cpu" -ge "$critical" ]
then
echo "CRITICAL - ${perfdata} | ${perfdata}"
exit $ST_CR
else
echo "OK - ${perfdata} | ${perfdata} "
exit $ST_OK
fi
else
echo "Usage Example: $PROGNAME -w 3 -c 12 -p firefox "
exit $ST_OK
fi
当前标题:nagios插件监控cpu,可pnp画图
链接地址:http://scyanting.com/article/gjppdj.html