设为首页 加入收藏

TOP

Nagios 监控MongoDB
2017-02-15 08:15:20 】 浏览:186
Tags:Nagios 监控 MongoDB

随着mongodb的广泛使用监控mongodb的业务现在已经变得十分重要了现在我们就来讨论一下nagios中mongodb的监控方法。


一:下载nagios-plugin-mongodb插件。


下载地址


https://github.com/mzupan/nagios-plugin-mongodb


二:把下载压缩包中的check_mongodb.py插件上传至nagios服务器。


把插件放置在nagios的libexec目录下如图



注意添加权限


# chown nagios.nagios check_mongodb.py
# chmod a+x check_mongodb.py


三:测试check_mongdb.py插件是否能用。


# ./check_mongodb.py --help


若是能够正常现实帮助选项则插件能够正常使用若显示no module named pymongo信息则要为系统安装pymongo模块。


四:下载安装pymongo。? ?


下载最新的pymongo2.7.1


1 # wget --no-check-certificate https://pypi.python.org/packages/source/p/pymongo/pymongo-2.7.1.tar.gz


安装pymongo?


# tar -zxvf pymongo-2.7.1.tar.gz
# cd pymongo-2.7.1
# python setup.py install


五:使用check_mongodb.py插件测试mongodb连接。? ? ? ?


如图



六:配置nagios。


配置命令


# vi /usr/local/nagios/etc/objects/commands.cfg
######check_mongodb########
define command {
? ? command_name? ? check_mongodb
? ? command_line? ? $USER1$/check_mongodb.py -H $ARG1$ -A $ARG2$ -P $ARG3$ -W $ARG4$ -C $ARG5$
}
define command {
? ? command_name? ? check_mongodb_database
? ? command_line? ? $USER1$/check_mongodb.py -H $ARG1$ -A $ARG2$ -P $ARG3$ -W $ARG4$ -C $ARG5$ -d $ARG6$
}
define command {
? ? command_name? ? check_mongodb_collection
? ? command_line? ? $USER1$/check_mongodb.py -H $ARG1$ -A $ARG2$ -P $ARG3$ -W $ARG4$ -C $ARG5$ -d $ARG6$ -c $ARG7$
}
define command {
? ? command_name? ? check_mongodb_replicaset
? ? command_line? ? $USER1$/check_mongodb.py -H $ARG1$ -A $ARG2$ -P $ARG3$ -W $ARG4$ -C $ARG5$ -r $ARG6$
}
define command {
? ? command_name? ? check_mongodb_query
? ? command_line? ? $USER1$/check_mongodb.py -H $ARG1$ -A $ARG2$ -P $ARG3$ -W $ARG4$ -C $ARG5$ -q $ARG6$
}


配置服务(以下分别监控连接,空闲连接,内存使用,复制集状态,库大小)


# vi /usr/local/nagios/etc/objects/localhost.cfg
######check_mongodb##########
define service{
? ? ? ? use? ? ? ? ? ? ? ? ? ? ? ? ? ? linux-service? ? ? ?
? ? ? ? host_name? ? ? ? ? ? ? ? ? ? ? 10.0.1.103
? ? ? ? service_description? ? ? ? ? ? check_mongodb_connect_54
? ? ? ? check_command? ? ? ? ? ? check_mongodb!10.0.1.54!connect!27017!2!4
? ? ? ? }
? define service{
? ? ? ? use? ? ? ? ? ? ? ? ? ? ? ? ? ? linux-service? ? ? ? ; Name of service template to use
? ? ? ? host_name? ? ? ? ? ? ? ? ? ? ? 10.0.1.103
? ? ? ? service_description? ? ? ? ? ? check_mongodb_connections_54
? ? ? ? check_command? ? ? ? ? ? ? ? ? check_mongodb!10.0.1.54!connections!27017!70!80
? ? ? ? }
define service{
? ? ? ? use? ? ? ? ? ? ? ? ? ? ? ? ? ? linux-service? ? ? ? ; Name of service template to use
? ? ? ? host_name? ? ? ? ? ? ? ? ? ? ? 10.0.1.103
? ? ? ? service_description? ? ? ? ? ? check_mongodb_memory_54
? ? ? ? check_command? ? ? ? ? ? ? ? ? check_mongodb!10.0.1.54!memory!27017!20!28
? ? ? ? }
define service{
? ? ? ? use? ? ? ? ? ? ? ? ? ? ? ? ? ? linux-service? ? ? ? ; Name of service template to use
? ? ? ? host_name? ? ? ? ? ? ? ? ? ? ? 10.0.1.103
? ? ? ? service_description? ? ? ? ? ? check_mongodb_rep_state_54
? ? ? ? check_command? ? ? ? ? ? ? ? ? check_mongodb!10.0.1.54!replset_state!27017!0!0
}
define service{
? ? ? ? use? ? ? ? ? ? ? ? ? ? ? ? ? ? linux-service? ? ? ? ; Name of service template to use
? ? ? ? host_name? ? ? ? ? ? ? ? ? ? ? 10.0.1.103
? ? ? ? service_description? ? ? ? ? ? check_mongodb_database_exam_54
? ? ? ? check_command? ? ? ? ? ? ? ? ? check_mongodb_database!10.0.1.54!database_size!27017!300!500!exam
}


七:测试语法重读nagios配置


# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg


若无错误重读配置


# service nagios reload


八:查看nagios监控页面验证结果。



如图所示监控配置完成。


可根据需求配置添加mongodb的各项监控指标内存数据库等。


更多MongoDB相关教程见以下内容


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MongoDB3.X版本的 的用户认证 下一篇使用DBMS_ROWID获取被阻塞行的row..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目