New Relic Now Dream of innovating more? Start living the dream in October.
RSVP Now

Getting started with MongoDB performance monitoring can be tricky. MongoDB Atlas has performance monitoring and reporting built-in, but many of the most valuable tools are only available for more expensive dedicated clusters. MongoDB Community Server is free, but collecting the data you need requires multiple disparate sources, making it challenging to create a comprehensive, cohesive overview of your database performance.

In this blog post, I’ll show you how to use the open-source MongoDB quickstart on New Relic Instant Observability to create a unified view of your MongoDB database performance. View throughput, collection size, connections, indexes, and more, all in a single dashboard.

What you need to know about MongoDB and monitoring

MongoDB is probably most well known for the source-available NoSQL database. But, MongoDB actually has several different database products. The source-available version is the Community Server, and they also have Enterprise Server and MongoDB Atlas. There’s also MongoDB Realm, but that’s a whole different thing that I won’t get into now. For this blog, I’ll concentrate on the popular versions, MongoDB Atlas and Community Server. 

NEW RELIC MONGODB INTEGRATION
MongoDB Logo
Start monitoring your MongoDB data today.
Install the MongoDB quickstart Install the MongoDB quickstart

 

MongoDB Atlas: a multi-cloud application data platform

“Multi-cloud application data platform” is how MongoDB describes Atlas. It is not only a hosted database, but a data platform. What’s the difference? MongoDB Atlas includes some additional features such as triggers, a Data API, and access management. However, the feature most relevant to this blog is the monitoring and metrics dashboard:

This monitoring is broken down into four main areas:

  • Overview
    The Overview tab gives you some basic information about your database cluster; how large it is, how many operations (reads/writes) it is performing, and the number of connections.
  • Metrics
    The Metrics tab is similar to the overview, showing size, operations, and connections. But here, you can see the breakdown per shard in your cluster. You can also change the granularity, and you can select a particular date and time range.
  • Real Time
    On the Real Time tab, you can use real-time metrics to identify slow queries and high traffic collections. But, this monitoring is only available if you pay for dedicated servers (M10 clusters or higher).
  • Profiler
    The Profiler tab is where you can view key performance statistics and diagnose slow-running operations—a keystone for any database administrator. However, like the real-time metrics, this too is only available for M10 clusters and higher.

If you don’t want to pay for hosting with Atlas, you can still use the Community Server of MongoDB.

Self-managed monitoring with MongoDB Community Server

The Community Server MongoDB database is almost identical to the database used by MongoDB Atlas. This parity is a key selling point because it allows you to progress from Community Server to Atlas— and even back again—as your scaling and management requirements change.

But, with the Community Server, you lose the "data platform" aspects of Atlas, including the monitoring and metrics dashboards.

You can approximate it using different tools. Since version 4.0, Community Server includes free cloud monitoring, which is similar to the general overview in Atlas. You can use mongostat and mongotop to view data broken down by shard, just like on the Metrics tab. Also, MongoDB Compass can show you near real-time performance data such as slow queries and hot collections, and these features are not locked behind a paywall like the Real Time and Profiler tabs in Atlas.

But pulling in the data you need from all these disparate sources is difficult. Some are in the browser, others the terminal, and MongoDB Compass is its own standalone application! This approach lacks the instant understanding of a single unified dashboard.

Instrument MongoDB with New Relic One

Instead of a hodge-podge of different tools, you can observe our MongoDB database entirely within New Relic One. 

1. Before you get started, you will need a MongoDB cluster or replica set to monitor. You will also need a listCollections role and a new user with both clusterMonitor and listCollections roles. You can create these in the MongoDB shell:

db.createRole({
    role: "listCollections",
    privileges: [{
        resource: {db:"",collection:""},
        actions: ["listCollections"]
    }],
    roles: []
})

2. Don’t forget to change the username and password!

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

Now that you have created the new role and user, you'll complete the rest of the installation using New Relic’s guided install.

Configure New Relic One 

The New Relic One guided install creates a customized CLI command for your environment that downloads and installs the New Relic CLI and the infrastructure agent. With one command, you'll get infrastructure and log data flowing in so you can start observing your system. The guided install also discovers and recommends integrations for greater visibility into your stack.

  1. If you don’t already have a New Relic One account,  sign up for free.
  2. Select Add more data in New Relic One, and then under Use our guided install, select Guided install.
  3. Follow the prompts on screen and run the generated command on your MongoDB replica servers.

As the installation runs in your terminal, it should update your browser in real time. (No matter how often I do this, this part always seems magical to me!)

A few moments after the guided install completes, you should see MongoDB events and metrics appearing in New Relic! 

Create a dashboard with the MongoDB quickstart

At this point, you could query your MongoDB data using NRQL and build your own dashboard. However, with the MongoDB quickstart, you can create a MongoDB dashboard with just a couple of clicks.

New Relic Instant Observability is a collection of open-source quickstarts that can help you quickly configure dashboards, instrumentation, and alerts. You can view the source of any quickstart using the View repo button. For example, the MongoDB quickstart source is available at github.com/newrelic/newrelic-quickstarts/tree/main/quickstarts/mongodb.

The MongoDB quickstart consists of two main files, config.yml and dashboards/mongodb.json, and several decorative images used on the quickstart page.

The config.yml is metadata for the quickstart. It contains information such as the quickstart's name, description, authors, and links to documentation.

The mongodb.json file is the blueprint for the dashboard. If you view the file on GitHub, you can see that it contains a list of widgets and their type, size, positioning, titles, and other information. This is the same file that JSON generates when you click the copy JSON to clipboard button on any of your dashboards (which is also how you could bootstrap your own quickstarts). For more information on creating your own quickstarts, view the newrelic-quickstarts repository.

  1. To add the MongoDB dashboard to your New Relic account, go to the MongoDB quickstart page and click Install quickstart.
  2. When you reach the MongoDB monitoring integration step in the installation, you can click Skip this step because you already installed the New Relic infrastructure agent and the MongoDB integration earlier. 
  3. After the quickstart finishes deploying, you can click See your data to jump directly to the dashboard.

Your new dashboard contains a wealth of information, including collection sizes, bytes in, bytes out, total commands, failed commands, requests per second, indexes, and available connections. The dashboard also includes multiple customized graphs and charts to help you better visualize the incoming data. Now you can get valuable real-time insights into the health and performance of your MongoDB clusters in a single interface without having to log into individual database instances.

This is just a quick way of starting a dashboard. You can customize it to suit your unique needs. 

Ready to start with New Relic? Try our New Relic Infrastructure monitoring today.