MongoDB monitoring integration

Gain deep insights into MongoDB performance with seamless data integration into New Relic. Monitor key metrics like throughput, collection size, connections, and indexes effortlessly, all within our powerful platform. Create alerts to stay ahead of spikes, build custom dashboards for tailored views, and proactively optimize your database monitoring.

Image of the dashboard available through the MongoDB quickstart

To get the most out of this page, select the installation method that fits your environment. You need a New Relic account before starting the installation process.

Tip

Use guided install to quickly see your data in the UI

The guided install is a single CLI command you can run to monitor your MongoDB instance. It's a good option for small organizations, or for anyone who wants to test out New Relic.

For a more permanent and scalable solution, we recommend the standard manual install of the agent: keep reading for how to do that.

Choose your framework

Choose your install path

How is your database hosted

Check the compatibility and requirements

  • Our integration is compatible with MongoDB 4.0 or higher, Percona Server, and MongoDB Atlas M10 or higher.
  • To monitor MongoDB Atlas, you'll need a hosted environment to install the infrastructure agent and integration and remotely connect to the Atlas instance.

Install the infrastructure agent

To use the MongoDB integration, you need to also install the infrastructure agent on the same host. The infrastructure agent monitors the host itself, while the integration you'll install in the next step extends your monitoring with MongoDB-specific data such as database and instance metrics.

Download using APT

  1. From the command line, run these commands:

    bash
    $
    sudo apt-get update
    bash
    $
    sudo apt-get install nri-mongodb3

Prepare MongoDB or Percona

Tip

Complete these steps on the mongos to be monitored. If you want to collect mongod-level metrics, such as host or replica set statistics, create the role and user on each mongod as well.

  1. In the MongoDB shell. switch to the admin database:

    bash
    $
    use admin
  2. Create a new user, and assign clusterMonitor and readAnyDatabase roles to the user (adjust the username and password as required).

    db.createUser({
    user: "username",
    pwd: "password",
    roles: [
    { role: "clusterMonitor", db: "admin" },
    { role: "readAnyDatabase", db: "admin" }
    ]
    })

For more information, check the MongoDB Atlas documentation.

Configure the MongoDB integration

  1. Change directory to the integrations configuration folder by running:

    bash
    $
    cd /etc/newrelic-infra/integrations.d
  2. Copy the sample configuration file by running:

    bash
    $
    sudo cp mongodb3-config.yml.sample mongodb3-config.yml
  3. Edit the mongodb3-config.yml file. The only two required fields are mongodb_cluster_name and mongodb_uri. This example config file collects all metrics:

    integrations:
    - name: nri-mongodb3
    config:
    mongodb_cluster_name: my_cluster
    mongodb_uri: mongodb://username:password@localhost:27017
    exporter_port: 9126

You can find all the config options at the bottom of this doc along with more complex config examples.

Find and use data

  1. Go to one.newrelic.com > Integrations & Agents and type MongoDB.

  2. Under Dashboards, click MongoDB overview dashboard. Installing the MongoDB dashboards

  3. In the popup window, select your account

  4. Click View dashboard, and see your MongoDB data in New Relic.

For more on how to find and use your data, see how to understand integration data. You can find a full list of metrics and their attributes at the bottom of this doc.

MongoDB config settings

The following configuration options are available:

Setting

Description

Default

mongodb_cluster_name

User-defined name to uniquely identify the cluster being monitored. Required

N/A

mongodb_uri

MongoDB connection URI. Required

N/A

mongodb_direct_connect

Whether or not a direct connect should be made. Direct connections are not valid if multiple hosts are specified or an SRV URI is used, for example for mongoDB Atlas.

Notice that direct connect should also be set to false if loadBalanced=true is specified either in the connection string or in the DNS entry as it happens in case of Serverless Atlas Deployments.

true

collection_filters

List of comma separated databases.collections. If empty, defaults to all databases and collections

N/A

index_filters

List of comma separated databases.collections to retrieve index stats. If empty, defaults to all indexes

N/A

database_stats

Enable/Disable collection of Database metrics

true

collection_stats

Enable/Disable collection of Collections metrics

true

index_stats

Enable/Disable collection of Index metrics

true

replicaset_stats

Enable/Disable collection of Replica Set metrics

true

top_stats

Enable/Disable collection of Top Admin metrics

true

diagnostic_stats

Enable/Disable collection of Diagnostic metrics

true

exporter_port

Port to expose scrape endpoint on, If this is not provided a random port will be used to launch the exporter

random-port

scrape_timeout

Time until a scrape request times out

5s

Metric data

These are the 3 entities created: MONGODB_INSTANCE, MONGODB_DATABASE, and MONGODB_COLLECTION.

The following dimensional metrics are captured scraping the exporter and linked to the entity MONGODB_INSTANCE

The following dimensional metrics are captured scraping the exporter and linked to the entity MONGODB_COLLECTION:

The following dimensional metrics are captured scraping the exporter and linked to the entity MONGODB_DATABASE: