Monitoring MongoDB

Configure the Server Density agent to monitor your MongoDB server to:

• Collect important metrics, such as performance, connections and slow queries
• Identify overall server slowdowns caused by the database server
• Monitor status of replication including state, lag and health

Monitored metrics

  • Asserts
    • Msg
    • Regular
    • Rollovers
    • User
    • Warning
  • Background Flushing
    • Last flush length
    • Flush length average
    • Seconds since last flash
  • Connections
    • Total created
    • Available
    • Current
  • Cursors
    • Timed Out
    • Total Open
  • Database Count
  • Database Stats
    • Average object size
    • Collections
    • DB stats data size
    • File size
    • Indexes
    • Index size
    • Namespace size
    • Num extents
    • Objects
    • Stats storage size
    • OK
    • Data file version
    • DB
    • Namespaces
  • Stats data size
  • Stats file size
  • Stats index size
  • Stats objects
  • Stats storage size
  • Extra Info
    • Heap usage
    • Page faults
  • Memory
    • Bits
    • Mapped
    • Mapped with journal
    • Resident
    • Virtual
  • Replication
    • Buffer count
    • Buffer max size bytes
    • Buffer size bytes
  • Opcounters
    • Command
    • Delete
    • Get more
    • Insert
    • Query
    • Update
  • Replication Opcounters
    • Command
    • Delete
    • Get more
    • Insert
    • Query
    • Update
  • Replication Set
    • Health
    • My state
    • Replication Log
    • Is master
    • Set name
    • Op time date
    • Is secondary
  • Members
    • State
    • Op time date
    • Last heartbeat
    • Name
    • My id
    • Master changed
  • Total open cursors
  • Uptime
  • Version

Installing the MongoDB plugin package

Install the MongoDB plugin on Debian/Ubuntu:

sudo apt-get install sd-agent-mongo

Install the MongoDB plugin on RHEL/CentOS:

sudo yum install sd-agent-mongo

Read more about agent plugins.

Configuring the agent to monitor MongoDB

1. Connect to the mongo shell and create a monitoring user (note this applies to MongoDB 3.0 upwards):

use admin
db.createUser({user: "serverdensity", pwd: "supersecretpassword", roles: [ "read","clusterAdmin","readAnyDatabase" ]})

2. Configure /etc/sd-agent/conf.d/mongo.yaml

  # Specify the MongoDB URI, with database to use for reporting (defaults to "admin")
  - server: mongodb://serverdensity:supersecretpassword@localhost:27017/admin 
  • If you run the database server on a non-standard port, you need to declare the path to the sock or want to execute check, amend the rest of the config file as necessary. 

3. Restart the agent

sudo /etc/init.d/sd-agent restart

Verifying the configuration
Execute info to verify the configuration with the following:

sudo /etc/init.d/sd-agent info 

If the agent has been configured correctly you’ll see an output such as:

  - instance #0 [OK]
  - Collected 32 metrics, 0 events & 1 service check

You can also check the metrics that the check is returning with the following command

sudo -u sd-agent /usr/share/python/sd-agent/ check mongo

Connecting over SSL

We can connect to your MongoDB instances using SSL but it may require some changes to the agent if you are using certificate files.

  • If you are not using certificate files

 You can just specify ?ssl=true in the connection string e.g. in step 2 of the installation instructions, then specify mongodb://hostname:port/?ssl=true as part of the config.

  • If you are using certificate files

If you are using cert files then you'll need to tell the agent where they are. Set these 4 lines in your {agentdir}/conf.d/mongo.yaml file:

ssl: True # Optional (default to False)
ssl_keyfile: /path/to/key.file
ssl_certfile: /path/to/cert.file

Recommended alerts

  • mongo.replSet.state - this is a numerical value of the current state of this server
  • mongo.globalLock.ratio - if this value is very high you may have be experiencing capacity problems
  • mongo.connections.current - this value shouldn't grow too much (under a few thousands for busy apps)
  • mongo.connections.available - this value should never get to 0
  • mongo.opcounters.* - this value indicates the activity of your server (consistent with your app behavior)
  • mongo.indexCounters.btree.missRatio - this value should be 0 or almost zero, otherwise you're missing indexes

Configuring graphs

Click the name of your server from the Devices list in your Server Density account then go to the Metrics tab. Click the + Graph button on the right then choose the MongoDB metrics to display the graphs. The metrics will also be available to select when building dashboard graphs.

Further Reading

We have a detailed blog post on how to monitor MongoDB.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Monday  —  Friday.

10am  —  6pm UK.

Dedicated Support.