Skip to content

Latest commit

 

History

History
 
 

README.md

MongoDB check

MongoDB Dashboard

Overview

Connect MongoDB to Datadog in order to:

  • Visualize key MongoDB metrics.
  • Correlate MongoDB performance with the rest of your applications.

You can also create your own metrics using custom find, count and aggregate queries.

Note: MongoDB v2.6+ is required for this integration.

Setup

Installation

The MongoDB check is included in the Datadog Agent package. No additional installation is necessary.

Configuration

Follow the instructions below to configure this check for an Agent running on a host. For containerized environments, see the Containerized section.

Host

Prepare MongoDB

In a Mongo shell, create a read-only user for the Datadog Agent in the admin database:

# Authenticate as the admin user.
use admin
db.auth("admin", "<YOUR_MONGODB_ADMIN_PASSWORD>")

# On MongoDB 2.x, use the addUser command.
db.addUser("datadog", "<UNIQUEPASSWORD>", true)

# On MongoDB 3.x or higher, use the createUser command.
db.createUser({
  "user":"datadog",
  "pwd": "<UNIQUEPASSWORD>",
  "roles" : [
    {role: 'read', db: 'admin' },
    {role: 'clusterMonitor', db: 'admin'},
    {role: 'read', db: 'local' }
  ]
})
Metric collection
  1. Edit the mongo.d/conf.yaml file in the conf.d folder at the root of your Agent's configuration directory. See the sample mongo.d/conf.yaml for all available configuration options.

    init_config:
    instances:
      ## @param server - string - required
      ## Specify the MongoDB URI, with database to use for reporting (defaults to "admin")
      ## E.g. mongodb://datadog:LnCbkX4uhpuLHSUrcayEoAZA@localhost:27016/admin
      #
      - server: "mongodb://datadog:<UNIQUEPASSWORD>@<HOST>:<PORT>/<DB_NAME>"
    
        ## @param replica_check - boolean - required - default: true
        ## Whether or not to read from available replicas.
        ## Disable this if any replicas are inaccessible to the agent.
        #
        replica_check: true
    
        ## @param additional_metrics - list of strings - optional
        ## By default, the check collects a sample of metrics from MongoDB.
        ## This  parameter instructs the check to collect additional metrics on specific topics.
        ## Available options are:
        ##   * `metrics.commands` - Use of database commands
        ##   * `tcmalloc` -  TCMalloc memory allocator
        ##   * `top` - Usage statistics for each collection
        ##   * `collection` - Metrics of the specified collections
        #
        additional_metrics:
          - metrics.commands
          - tcmalloc
          - top
          - collection
  2. Restart the Agent.

Log collection

Available for Agent versions >6.0

  1. Collecting logs is disabled by default in the Datadog Agent, enable it in your datadog.yaml file:

    logs_enabled: true
  2. Add this configuration block to your mongo.d/conf.yaml file to start collecting your MongoDB logs:

    logs:
      - type: file
        path: /var/log/mongodb/mongodb.log
        service: mongo
        source: mongodb

    Change the service and path parameter values and configure them for your environment. See the sample mongo.yaml for all available configuration options

  3. Restart the Agent.

Containerized

For containerized environments, see the Autodiscovery Integration Templates for guidance on applying the parameters below.

Metric collection
Parameter Value
<INTEGRATION_NAME> mongo
<INIT_CONFIG> blank or {}
<INSTANCE_CONFIG> {"server": "mongodb://datadog:<UNIQUEPASSWORD>@%%host%%:%%port%%/<DB_NAME>", "replica_check": true, "additional_metrics": ["metrics.commands","tcmalloc","top","collection"]}
Log collection

Available for Agent versions >6.0

Collecting logs is disabled by default in the Datadog Agent. To enable it, see Docker log collection.

Parameter Value
<LOG_CONFIG> {"source": "mongodb", "service": "mongo"}

Validation

Run the Agent's status subcommand and look for mongo under the Checks section.

Data Collected

Metrics

See metadata.csv for a list of metrics provided by this check.

See the MongoDB 3.0 Manual for more detailed descriptions of some of these metrics.

NOTE: The following metrics are NOT collected by default, use the additional_metrics parameter in your mongo.d/conf.yaml file to collect them:

metric prefix what to add to additional_metrics to collect it
mongodb.collection collection
mongodb.commands top
mongodb.getmore top
mongodb.insert top
mongodb.queries top
mongodb.readLock top
mongodb.writeLock top
mongodb.remove top
mongodb.total top
mongodb.update top
mongodb.writeLock top
mongodb.tcmalloc tcmalloc
mongodb.metrics.commands metrics.commands

Events

Replication state changes:
This check emits an event each time a Mongo node has a change in its replication state.

Service Checks

mongodb.can_connect:
Returns CRITICAL if the Agent cannot connect to MongoDB to collect metrics, otherwise returns OK.

Troubleshooting

Need help? Contact Datadog support.

Further Reading

Read our series of blog posts about collecting metrics from MongoDB with Datadog: