Rants and musings of Paul Scott
Paul Scott on 2012-04-12 10:21:11
How to monitor your MongoDB server(s) and ReplicaSets with Nagios on UbuntuI needed to use Nagios to monitor a mongodb server (OK, my localhost as an experiment) and after a little poking around, managed this with relative ease.
These are the steps (I used nagios3 out of the Ubuntu repository)
1. Install Nagios3
2. Fix the SSH and disk error issues according to http://ubuntuforums.org/showthread.php?t=1749248
3. git clone https://github.com/mzupan/nagios-plugin-mongodb to /usr/lib/nagios/plugins/nagios-plugin-mongodb
4. Add the following commands to /etc/nagios3/commands.cfg
define command {
command_name check_mongodb
command_line /usr/lib/nagios/plugins/nagios-plugin-mongodb/check_mongodb.py -H $HOSTADDRESS$ -A $ARG1$ -P $ARG2$ -W $ARG3$ -C $ARG4$
}
define command {
command_name check_mongodb_database
command_line /usr/lib/nagios/plugins/nagios-plugin-mongodb/check_mongodb.py -H $HOSTADDRESS$ -A $ARG1$ -P $ARG2$ -W $ARG3$ -C $ARG4$ -d $ARG5$
}
5. touch /etc/nagios3/conf.d/mongodb_nagios2.cfg
6. add the following service definitions to the above file. Use your brain here a bit, so for example, if you do not run a replicaSet configuration on MongoDB, leave that service definition out, else it will produce CRITICAL warns the whole time and annoy you.
define service {
use generic-service
hostgroup_name mongodb-servers
service_description Mongo Connect Check
check_command check_mongodb!connect!27017!2!4
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description Mongo Free Connections
check_command check_mongodb!connections!27017!70!80
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description Mongo Replication Lag
check_command check_mongodb!replication_lag!27017!15!30
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description Mongo Memory Usage
check_command check_mongodb!memory!27017!20!28
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description Mongo Lock Percentage
check_command check_mongodb!lock!27017!5!10
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description Mongo Flush Average
check_command check_mongodb!flushing!27017!100!200
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description Mongo Last Flush Time
check_command check_mongodb!last_flush_time!27017!200!400
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description MongoDB state
check_command check_mongodb!replset_state!27017!0!0
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description MongoDB state
check_command check_mongodb!index_miss_ratio!27017!.005!.01
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description MongoDB Number of databases
check_command check_mongodb!databases!27017!300!500
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description MongoDB Number of collections
check_command check_mongodb!collections!27017!300!500
}
define service {
use generic-service
hostgroup_name mongodb-servers
service_description MongoDB Database size YOUR-dbname
check_command check_mongodb_database!database_size!27017!300!500!YOUR-dbname
}
see the bit that says YOUR-dbname in the final service? Yeah, you need to change that to an actual db name...
7. Do a quick sanity check on your configs
nagios3 -v /etc/nagios3/nagios.cfg
if you get something like:
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
you should be good to go.
8. Restart nagios3 with /etc/init.d/nagios3 restart
9. Check the web interface for nagios3 to see information about your MongoDB services!
10. Have some milk and a cookie, you deserve it!
Comments for this post
balasundaram On Wed, 22 Aug 2012 10:44:22 +0200
If possible add client side nrpe configuration for mongodb plugin. Thanks
aali.ramzan On Wed, 18 Jul 2012 15:38:45 +0200
Hi
I have installed pymongo .
Command is running successfully on both server nagios server and remote side
[root@Mongo plugins]# ./check_mongodb.py -H localhost -p 27017
OK - Connection took 0 seconds
root@AdServer-LoadBalancer libexec]# ./check_mongodb.py -H 10.180.86.108 -p 27017
OK - Connection took 0 seconds
but nagios show NRPE: Unable to read output I tried my best to resolved it but its not working any advise remaining checks are working perfectly.

