为了及时跟踪最近的一个问题并处理问题,于是乎写了一个监控mongodb队列的脚本,由于自写的脚本没有返回status代码,所以状态一直显示为OK,也就是到不得想要的结果!同时在nagios服务器上使用./chech_nrp -H ip -c check_mongoqueue 时显示的结果也是对的,但是我忘记了返回的状态代码是不会显示的!!
# Version 0.0.1 -2013/04/11
# by shibaolan
#
#
mongostat=/kingdee/mongodb/bin/mongostat
function help {
echo -e "\n\tThis plugin shows mongostat queue.\n\t-w \tSets the WARNING level for mongo queue.\n\t-c \tSets the CRITICAL level for mongo queue.\n"
exit -1
}
# Ensuring we have the needed tools:
( [ ! -f $mongostat ] ) && \
( echo "ERROR: You must have mongostat to run this plugin" && exit -1 )
# Getting parameters:
#while getopts "w:c:h" OPT; do
while getopts "w:c:h" OPT; do
case $OPT in
"w") warning=$OPTARG;;
"c") critical=$OPTARG;;
"h") help;;
esac
done
[ -z "$warning" ] && echo "ERROR: You must specify all warning and critical levels" && help
[ $warning -ge $critical ] && echo "ERROR: critical levels must be highter than warning levels" && help
myqueue=`$mongostat -n 1 -noheaders |grep -v connected |awk '{print $14}'|awk -F "|" '{print $1}'`
#myqueue=`$mongostat -n 1 -noheaders |grep -v connected|awk '{print $3}'`
# Printing the results:
if [ $myqueue -ge $critical ];then
msg="CRITICAL"
#下一行为解决问题增加
status=2
elif [ $myqueue -lt $warning ];then
msg="OK"
#下一行为解决问题增加
status=0
else
msg="WARNING"
#下一行为解决问题增加
status=1
fi
echo -e "$msg - mongodbqueue $myqueue|qr=$myqueue"
#下一行为解决问题增加
exit $status
阅读(3688) | 评论(0) | 转发(0) |