标签:nagios 监控 mongodb 解决nagios界面显示null 问题
网上有很多关于nagios 监控mongodb 的介绍,但是无一例外,手工执行 python 能获取客户端的值,nagios 监控界面上面显示null, 针对该问题,本人用shell 脚本重新封装了部分监控选项,让nagios 能正常监控mongodb 服务器
如果想了解nagios 监控mongodb的部署过程,请点击:
http://www.2cto.com/database/201410/341855.html
https://github.com/mzupan/nagios-plugin-mongodb/blob/master/README.md
实现原理:
利用shell 脚本 获取 check_mongodb.py 的 值,然后传给nagios 实现nagios 警告
centos5.8 64bit
python2.4.3
pymongo 1.9
tar -xvzfpymongo-1.9.tar.gz
cd pymongo-1.9
pythonsetup.py install
[root@P-masternagios-plugin-mongodb]# python
Python2.4.3 (#1, Feb 22 2012, 16:05:45)
[GCC4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type"help", "copyright", "credits" or"license" for more information.
>>>import pymongo
>>>pymongo.version
‘1.9‘
>>>import sys
>>>sys.exit()
mv nagios-plugin-mongodb-bycsc.zip /usr/local/nagios/libexec/
unzip nagios-plugin-mongodb-bycsc.zip
chown -Rnagios:nagios /usr/local/nagios/libexec/nagios-plugin-mongodb
chmod -R755 /usr/local/nagios/libexec/nagios-plugin-mongodb
执行check_mongodb.py 看是否能正常运行,如下显示说明正常运行
[root@P-masternagios-plugin-mongodb]# ./check_mongodb.py -h
。。。省略
-c COLLECTION, --collection=COLLECTION
Specify the collectionto check
-T SAMPLE_TIME, --time=SAMPLE_TIME
Time used to samplenumber of pages faults
具体参数请参考:/usr/local/nagios/libexec/nagios-plugin-mongodb/check_mongodb.sh脚本
*/10 * * * * /usr/local/nagios/libexec/nagios-plugin-mongodb/check_mongodb.sh 10.0.8.17 ALL 30000
*/10 * * * * /usr/local/nagios/libexec/nagios-plugin-mongodb/check_mongodb.sh 10.0.8.18 ALL 30000
*/10 * * * * /usr/local/nagios/libexec/nagios-plugin-mongodb/check_mongodb.sh 10.0.8.19 ALL 30000
利用定时任务,把以上服务器的状态检查结果重定向到/tmp文件夹下
vi /usr/local/nagios/etc/objects/commands.cfg 添加:
definecommand {
command_name check_mongodb
command_line /usr/local/nagios/libexec/nagios-plugin-mongodb/check_mongodb.sh ‘$HOSTADDRESS$‘ ‘$ARG1$‘ ‘$ARG2$‘
}
命令解说:
/usr/local/nagios/libexec/nagios-plugin-mongodb/check_mongodb.sh IP地址 监控选项 端口
check_mongodb.py监控选项可以有如下:
usage:check_mongodb.py [options]
check_mongodb.py:error: option -A: invalid choice: ‘memordfd‘ (choose from ‘connect‘,‘connections‘, ‘replication_lag‘, ‘replication_lag_percent‘, ‘replset_state‘,‘memory‘, ‘memory_mapped‘, ‘lock‘, ‘flushing‘, ‘last_flush_time‘,‘index_miss_ratio‘, ‘databases‘, ‘collections‘, ‘database_size‘,‘database_indexes‘, ‘collection_indexes‘, ‘collection_size‘, ‘queues‘, ‘oplog‘,‘journal_commits_in_wl‘, ‘write_data_files‘, ‘journaled‘, ‘opcounters‘,‘current_lock‘, ‘replica_primary‘, ‘page_faults‘, ‘asserts‘,‘queries_per_second‘, ‘page_faults‘, ‘chunks_balance‘, ‘connect_primary‘,‘collection_state‘, ‘row_count‘, ‘replset_quorum‘)
目前check_mongodb.sh只是配置了 ‘connect‘ ‘connections‘ replset_state ‘memory‘ 选项
可以参考 README.md 列子进行配置!
在nagios 账户下运行命令检查mongodb服务器:(nagios账户下面执行)
su -nagios
# su - nagios
$/usr/local/nagios/libexec/nagios-plugin-mongodb/check_mongodb.sh 10.0.8.19memory 30000
OK -Memory Usage: 0.04GB resident, 0.78GB virtual, 0.08GB mapped, 0.16GBmappedWithJournal
如显示以上结果,则通过
[root@P-masternagios-plugin-mongodb]# cat /usr/local/nagios/etc/objects/server-8-17.cfg
definehost{
use linux-server
host_name server-8-17
alias server-8-17
address 10.0.8.17
}
defineservice{
use generic-service
host_name server-8-17
service_description SSH
check_command check_ssh
}
......省略其他配置文件
#检测mongodb服务的连接时间
defineservice{
use generic-service
host_name server-8-17
service_description check mongodb connect 30000
check_command check_mongodb!connect!30000
}
#检查mongodb的连接数
defineservice{
use generic-service
host_name server-8-17
service_description check mongodb connections 30000
check_command check_mongodb!connections!30000
}
#检查mongodb内存使用率
defineservice{
use generic-service
host_name server-8-17
service_description check mongodb memory 30000
check_command check_mongodb!memory!30000
}
#mongo复制的状态
defineservice{
use generic-service
host_name server-8-17
service_description check mongodb replset state 30000
check_command check_mongodb!replset_state!30000
}
#检查mongodb复制完成的百分比率确保primary和standby的time是一致的
defineservice{
use generic-service
host_name server-8-17
service_description check mongodb replication lag 30000
check_command check_mongodb!replication_lag!30000
}
备注:
检查筏值 请在/usr/local/nagios/libexec/nagios-plugin-mongodb/check_mongodb.sh 里面配置 -W -C 参数
上传 自带脚本 /usr/local/nagios/libexec/nagios-plugin-mongodb/check_mongodb.sh
nagios 监控 mongodb 解决nagios界面显示null 问题
标签:nagios 监控 mongodb 解决nagios界面显示null 问题
原文地址:http://2574526.blog.51cto.com/2564526/1663317