5.7. Use a Prometheus Exporter to Monitor MongoDB

MongoDB Exporters are essential tools for monitoring MongoDB instances, providing valuable insights into their performance and health. Speedgain for Databases offers a function to gather that performance data, stores it in its own database, and offers a dashboard to analyze the values alongside native Speedgain databases.

In this guide, we’ll walk you through the process of setting up a MongoDB Exporter.

5.7.1. Prerequisites

  • Access to a MongoDB instance.

  • Basic knowledge of Linux terminal commands.

  • Docker installed on your system (optional but recommended for easy setup).

5.7.2. Step 1: Installation

  1. Navigate to the official GitHub repository for the Percona MongoDB Exporter by following this link: https://github.com/percona/mongodb_exporter.

  2. Follow the installation instructions provided in the repository’s README file.

  3. Ensure you have all the necessary dependencies installed as per the instructions.

5.7.3. Step 2: Configuration

  1. Once the exporter is installed, you’ll need to configure it to connect to your MongoDB instance.

  2. Prepare a mongodb_uri string with the connection string to your MongoDB instance.

  3. Add the flag --discovering-mode to enable autodiscover collections

  4. Add the flag --collect-all to enable all collectors. You would not see much without this flag.

Example mongodb_uri with credentials

mongodb://<user>:<password>@<hostname>:<port>

5.7.4. Step 3: Running the Exporter

  1. Start the Percona MongoDB Exporter using Docker. You can run the exporter in a container with the following commands:

docker pull percona/mongodb-exporter
docker run -d -p 9216:9216 --name mongodb_exporter percona/mongodb_exporter --mongodb.uri=<your_prepared_mongodb_uri> --discovering-mode --collect-all

5.7.5. Step 4: Verify Exporter Metrics

  1. Once the exporter is running, open a web browser and navigate to http://localhost:9216/metrics.

  2. You should see a page displaying various metrics related to your MongoDB instance.

  3. Verify that the metrics are being collected correctly.

5.7.6. Step 5: Setting Up a Remote Node in the Speedgain Configuration

  1. Access the Speedgain configuration interface, using your admin credentials, and navigate to the Nodes tab.

  2. Click on the "+" symbol located at the bottom left corner to create a new remote node if necessary.

  3. Provide an appropriate display name and input the hostname or IP address of the server where the MongoDB Exporter is running. Optionally, configure additional fields. For the port meant for OS monitoring, set it to 22. Select the operating system type for the remote system.

  4. Save the configuration.

5.7.7. Step 6: Setting Up a Database in the Speedgain Configuration

  1. In the Speedgain configuration interface, go to the databases tab.

  2. Click on the "+" symbol at the bottom left to create a new database configuration.

  3. Select MongoDB as the DBMS.

  4. Choose the remote node created in Step 5.

  5. Enter "metrics" in the metrics path and the port you configured for the MongoDB Exporter (default is 9216).

  6. No need to input login or SSL information.

  7. Provide an appropriate display name.

  8. Select the appropriate monitoring policy.

  9. If you want to initiate monitoring immediately, check the enabled checkbox.

  10. Save the configuration.

5.7.8. Step 7: Start Analyzing Your Database

  1. Navigate to the Speedgain start page by clicking on the header link "ITGAIN Speedgain for Databases".

  2. Click on "Overview Dashboards" located in the top right corner.

  3. Select "MongoDB - Overview" from the options.

  4. Begin analyzing your database. Please note that it may take a few minutes until the performance data becomes available.