A Node.js package that constantly monitors your MongoDB replica set to keep it healthy.
APACHE-2.0 License
A Node.js package that constantly monitors your MongoDB replica set to keep it healthy by checking the following:
mongod
process on each member isn't consuming too much RAM (to avoid the OS from killing the process due to low memory)When any of these conditions are not met, mongomonitor
alerts you via e-mail or Slack so you can fix the issue ASAP.
First, install the package using npm:
npm install -g mongomonitor
Then, create a file called config.js
and paste the following inside it:
module.exports = {
// Main database to monitor
database: 'app',
// MongoDB replica set members
members: [
'db1.example.com',
'db2.example.com',
'arbiter1.example.com'
],
// Database authentication
auth: {
username: 'user',
password: 'a1b2c3d4f5',
authSource: 'admin' // The database to authenticate against
},
// SMTP configuration for sending alert e-mails (delete to disable)
smtp: {
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: 'password'
},
address: '[email protected]'
},
// Slack configuration for sending alert messages through webhook (delete to disable)
slack: {
channelUrl: 'https://hooks.slack.com/services/xxx/xxx/xxx',
notifyMembers: ['john', 'sophia'] // enter slack user names here
},
// Name of the preferred primary member (leave blank to disable checking)
preferredPrimaryMember: '',
// Number of seconds to wait in between health checks
interval: 30,
// Minimum number of members within your replica set
minReplicaSetMembers: 3,
// Maximum number of minutes for a member to be disconnected from another member
maxHeartbeatThreshold: 3,
// Maximum number of minutes for a secondary to lag behind while replicating from the primary's oplog
maxReplicationDelay: 45,
// Minimum number of minutes that each member's oplog must contain to survive a replica set data member failure
minOplogLength: 60,
// Maximum RAM memory (GB) each member's mongod process may occupy
maxMongodMemory: 15,
// Max database disk storage size (in MB) each member may utilize
maxDatabaseSize: 12500
};
Modify the configuration file according to your replica set, especially the following parameters:
database
- the name of your main databasemembers
- the hostnames of all of your replica set membersauth
- the database authentication username/passwordsmtp
(optional) - the SMTP e-mail configuration for sending alerts (using Gmail, AWS SES, etc)slack
(optional) - the Slack webhook configuration for sending alert messagesTest the SMTP configuration by running:
mongomonitor --test-email
Check the console for SMTP errors. If there are no SMTP errors, check your configured e-mail for the test e-mail.
Finally, run mongomonitor
from the same directory as your config.js
to actually start monitoring:
mongomonitor
Observe the terminal output for any initial errors. If no errors are emitted, your MongoDB deployment is currently in good health.
Leave the tool running on a remote server by executing the following command:
mongomonitor > /tmp/mongomonitor-out.log 2> /tmp/mongomonitor-error.log &
If you want to keep your process running uninterrupted (recommended), it is advisable to use a process manager like PM2 or forever.
Apache 2.0