Giter Site home page Giter Site logo

sumitsk20 / mongomonitor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eladnava/mongomonitor

1.0 2.0 0.0 72 KB

A Node.js package that constantly monitors your MongoDB replica set to keep it healthy.

License: Apache License 2.0

JavaScript 100.00%

mongomonitor's Introduction

mongomonitor

npm version

A Node.js package that constantly monitors your MongoDB replica set to keep it healthy by checking the following:

  • The overall health status of the replica set
  • The minimum number of replica set members
  • The existence of a primary replica set member and at least one secondary
  • The health status of each replica set member, from the point of view of each member
  • The number of voting members in the replica set is odd, not even (for election voting majority)
  • The heartbeat timestamp between members is relatively low (indicating stable communication)
  • The oplog date on secondary members is relatively recent (so that they don't fall too far behind on replication)
  • The oplog length on each member is long enough to survive extended data member failures (for secondaries to catch up in case they were offline for a long period)
  • The primary database disk utilization doesn't exceed a certain size (to avoid running out of disk space without notice)
  • The 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.

Email Preview

Preview

Slack Preview

Preview

Usage

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 database
  • members - the hostnames of all of your replica set members
  • auth - the database authentication username/password
  • smtp (optional) - the SMTP e-mail configuration for sending alerts (using Gmail, AWS SES, etc)
  • slack (optional) - the Slack webhook configuration for sending alert messages

Test 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.

License

Apache 2.0

mongomonitor's People

Contributors

eladnava avatar jyotman avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.