Lesson 7: Self-Managed Monitoring / Learn

Video Transcript (English)

Welcome back! By now you’ve seen the power of MongoDB Atlas metrics and dashboards.

We also took a glance at 3rd party integrations and showcased one of them.

Now how do we monitor a self-managed deployment?

Manager to monitor your self-managed deployments.

But, sometimes that may not be an option. Can we use what we have learned so far?

In this video, we’re going to use the Prometheus and Grafana setup from our previous lesson on integrations and reconfigure it to source metrics from a self-managed deployment. If you haven’t already, or simply need a refresher, check out our lesson on Atlas Integrations!

You may recall that metrics are gathered by Prometheus from MongoDB Atlas via the integration.

At this time, Prometheus cannot directly collect metrics from a MongoDB self-managed deployment.

However, the folks at Percona have created an open source utility that allows Prometheus to collect metrics from our self-managed deployment.

The Percona MongoDB exporter is an open source tool that handles metrics from a MongoDB deployment. It retrieves data from diagnostic commands, like serverStatus, by looping over all exposed fields.

We are going to configure it as a Prometheus target. This means that Prometheus will have access to the metrics retrieved by the exporter and Prometheus can then make those metrics available to Grafana just as it did when it was connected to MongoDB Atlas.

Let’s begin by installing the Percona MongoDB exporter.

First we download the latest version of the exporter.

Then we extract the downloaded tarball.

Next, we move the binary to the /usr/local/bin/ directory.

The Percona MongoDB Exporter needs to connect to our deployment as a user. This user must have sufficient privilege to read MongoDB metrics but nothing else.

Which built-in role should we use?

If you guessed clusterMonitor you are correct!

First let’s connect to the MongoDB Shell.

And switch to the admin database.

Now let’s create our monitoring user with the clusterMonitor role.

The output shows we successfully created a new user so let’s exit the shell.

Next, we create a new systemd service file for the Percona MongoDB exporter and have it run as the prometheus user.

Notice we are specifying the MongoDB user credentials within the service file. This is not really a best practice for a production environment but sufficient for our demonstration.

We assume our self-managed instance is co-located with the exporter and specify localhost in the connection string.

Let’s save and exit.

Now we need to restart the system daemon to reload the unit files.

And then start the Percona MongoDB exporter system service.

Next we enable the exporter system service so that it automatically starts on boot.

Great - we can confirm that the exporter system service is running and enabled by reviewing its status.

Now that we see that it is active, we can query the new service API to confirm MongoDB metrics are being collected.

Great - we can see from the long output that the Percona MongoDB exporter is gathering metrics from our MongoDB deployment.

Prometheus needs to be told about our Percona MongoDB exporter service.

We do this by adding a scrape target to the Prometheus configuration.

Here, we are adding a new job definition under the scrape configs section that includes the default port for the exporter.

Let’s save and exit.

And now we need to restart the prometheus system service to apply the configuration change.

Finally, let’s use the Prometheus server API to confirm that the local exporter target is present and healthy.

Nice, we can see the Percona MongoDB exporter listed in the output.

We’ve just configured the Percona MongoDB exporter to collect metrics for our deployment and set up Prometheus to scrape those metrics from the exporter. We already have Grafana up and running, so now let’s see our Grafana visualizations of our self-managed deployment!

Here’s an example of a dashboard that has already been built in Grafana. Here, we are displaying charts that show <metrics>.

You can build and configure your own visualizations based on the needs of your deployment.

Checkout all the available metrics in the Grafana UI.

Great job! Let’s recap what you learned in this video:

You learned how to install and configure the Percona MongoDB exporter on Ubuntu Linux.

You also learned how to configure the exporter as a Prometheus target and visualize the metrics on our existing Grafana dashboard!