Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1602074
  • 博文数量: 184
  • 博客积分: 3044
  • 博客等级: 中校
  • 技术积分: 2467
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-25 15:04
文章分类

全部博文(184)

文章存档

2022年(4)

2021年(3)

2020年(1)

2019年(5)

2018年(13)

2017年(6)

2016年(10)

2015年(11)

2014年(11)

2013年(13)

2012年(23)

2011年(25)

2010年(2)

2008年(1)

2007年(5)

2006年(51)

分类: 系统运维

2013-04-15 11:20:06

为了及时跟踪最近的一个问题并处理问题,于是乎写了一个监控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
阅读(3595) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~