- Overview
- Requirements
- Usage
- [Nagios configuration](#Nagios configuration)
- Development
This script is a nagios plugin, to check the state of MongoDB. It's written in Bash, to avoid any dependencies with PyMongo, venv and even Python.
Why ? Because in a perfect world, your production database should be as lightweight as possible, right ? ;)
The design of the script is quite easy, in order to allow you to contribute with your own needs. Basically, one check is one function, keep it simple.
Nagios : https://www.nagios.org/ MongoDB : https://www.mongodb.com/
- bash
- awk
- mongodb-org-shell
You need MongoDB repository : https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
$ sudo apt-get install mongodb-org-shellYou need MongoDB repository : https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
$ sudo yum install -y mongodb-org-shellUsage: check_mongo.bash -t [standalone|replicaset] -h [hostname] -c [check_name]
Optional :
-u [username]
-p [password]
-w [port]
-v verbose
Any rs.xxx command has to be associated with -t replicaset
check_name :
mem.resident  Check resident memory usage (amount of physical memory being used, only for MMAPv1 storage engine)
rs.status     Status of the local node
rs.count      Count how many member are in the replicaset
rs.lag        Check replication lag$ /usr/lib/nagios/plugins/check_mongodb.bash -t replicaset -h database1-1.domain -u username -p password -c rs.status
$ OK - State is PRIMARY$ /usr/lib/nagios/plugins/check_mongodb.bash -t replicaset -h database1-1.domain -u username -p password -c rs.lag
$ OK : Lag replication is 0 hr(s)$ /usr/lib/nagios/plugins/check_mongo.bash -t standalone -h database1-2 -c mem.resident
NOK : Resident memory used : 96%, readahead probably too highNagios side : /etc/nagios/databases/database1/mongodb.cfg
define service {
  host_name database1
  service_description Check status of MongoDB in replicaset
  check_command check_nrpe!check_mongodb_status
  use service-1m-24x7-mail
}
Client side : /etc/nagios/nrpe.d/mongodb.cfg
command[check_mongodb_status] = /usr/lib/nagios/plugins/check_mongodb.bash -t replicaset -h localhost -u username -p password -c rs.status
Feel free to contribute on GitHub.
    ╚⊙ ⊙╝
  ╚═(███)═╝
 ╚═(███)═╝
╚═(███)═╝
 ╚═(███)═╝
  ╚═(███)═╝
   ╚═(███)═╝