# Monitor MongoDB Databases

## Overview

This tutorial demonstrates how to view metrics for MongoDB Enterprise clusters. The [<mark style="color:blue;">Grafana</mark>](https://grafana.com/grafana) instance, which is connected to the [<mark style="color:blue;">Logging Service</mark>](https://docs.ionos.com/cloud/observability/logging-service) pipeline, is used to provide the data visualization of the metrics. By collecting metrics with a monitoring system, such as Prometheus through the official MongoDB exporter, and visualizing them in a Grafana dashboard, you can instantly detect anomalies, set proactive alerts on SLA-critical thresholds, troubleshoot latency or contention issues, and plan capacity upgrades with data-driven confidence.

MongoDB offers a set of observable metrics that describe the following:

* Server’s health and performance.
* Replication state—from low‑level resource usage such as CPU, memory, disk I/O, and network.
* Server‑wide counters such as connections, operations per second, cache hits, and page faults.
* Detailed replica‑set statistics such as election timestamps, primary‑secondary lag, and write‑concern success rates.
* Per‑command activity such as query, insert, update, delete, getMore, and lock counts.

MongoDB metrics turn raw runtime data into actionable insight, enabling reliable operations, faster incident resolution, and efficient resource utilization for any production deployment.

### Metrics for MongoDB

The following metrics are offered to gauge the health of the MongoDB clusters.

<details>

<summary><strong>CPU and Memory</strong></summary>

| **Metric**                                       | **Description**                                                                                                                                                                                              |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`ionos_dbaas_mongodb_cpu_rate5m`**             | An average CPU usage of the cluster over 5 minutes. It displays how much processor capacity the database is using. Monitor this metric to gauge if the CPU usage is operating closer to its resource limits. |
| **`ionos_dbaas_mongodb_memory_total_bytes`**     | The maximum memory allocated values, measured in bytes. It refers to the fixed memory limit for the instance.                                                                                                |
| **`ionos_dbaas_mongodb_memory_available_bytes`** | The remaining free memory in the cluster, measured in bytes. A lower value indicates that the database has limited available memory.                                                                         |

</details>

<details>

<summary><strong>Storage and Disk</strong></summary>

| **Metric**                                                     | **Description**                                                                                                                              |
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **`ionos_dbaas_mongodb_storage_total_bytes`**                  | The maximum storage capacity allocated values in bytes.                                                                                      |
| **`ionos_dbaas_mongodb_storage_available_bytes`**              | The remaining free storage space in the cluster, measured in bytes. A lower value indicates that the database has limited available storage. |
| **`ionos_dbaas_mongodb_disk_io_time_weighted_seconds_rate5m`** | The average time the disk spends handling read or write operations. A higher value indicates that the disk is busy.                          |

</details>

<details>

<summary><strong>Connections and Health</strong></summary>

| **Metric**                                  | **Description**                                                                                                                                                                                                        |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`ionos_dbaas_mongodb_connections_count`** | The total number of active client connections to the cluster. If the value is near the maximum count, new connections may fail. Monitor connections to determine whether the current connection limits are sufficient. |
| **`ionos_dbaas_mongodb_health`:**           | Indicates whether the cluster is healthy or not. If the value is 1, the cluster is considered healthy; if the value is 0, the cluster is considered unhealthy.                                                         |

</details>

<details>

<summary><strong>Query Patterns</strong></summary>

| **Metric**                                      | **Description**                                                                                                                                           |
| ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`ionos_dbaas_mongodb_scan_and_order_rate5m`** | Scans and orders data using an in-memory sort. It is averaged over a 5-minute window. Monitor this metric to determine whether your queries need indexes. |

</details>

<details>

<summary><strong>Indexes</strong></summary>

| **Metric**                                  | **Description**                                                                                                                 |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| **`ionos_dbaas_mongodb_index_count_total`** | The total number of indexes across collections. Monitor this metric to review unused indexes and free up memory and disk space. |
| **`ionos_dbaas_mongodb_index_size_bytes`**  | The total disk size of all indexes in the database, measured in bytes. Monitor this metric to manage your indexes.              |

</details>

<details>

<summary><strong>Cluster or Replica Set State</strong></summary>

| **Metric**                               | **Description**                                                                                                                              |
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **`ionos_dbaas_mongodb_instance_count`** | The total number of MongoDB instances, which together form a replica set. If the count is lower, then a node may be down.                    |
| **`ionos_dbaas_mongodb_member_state`**   | The state of the replica set member. If the value is 1, it is in a `PRIMARY` state, and a value of 2 indicates it is in a `SECONDARY` state. |

</details>

<details>

<summary><strong>Replication or Oplog</strong></summary>

| **Metric**                                                            | **Description**                                                                                                                                                                                                                                                                                                                            |
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`ionos_dbaas_mongodb_oplog_size_bytes`**                            | The size of the operations log, measured in bytes. It stores recent database changes, which act as a buffer to create replicas. Monitor this metric to ensure it is not smaller than the write activity, as this may lead to replication delays.                                                                                           |
| **`ionos_dbaas_mongodb_oplog_window_seconds`**                        | The time span of the operations logs up to where the replicas are possible. It is measured in seconds. Monitor this metric to ensure the operations log window is not too short, as this can cause replication to slow down.                                                                                                               |
| **`ionos_dbaas_mongodb_replication_headroom_seconds`**                | The maximum replication lag, measured in seconds, among all secondary members in a MongoDB replica set. This metric indicates how far behind the most delayed secondary is compared to the primary. Monitor this metric to keep replication lag minimal and ensure data consistency and reliable failover behavior across the replica set. |
| **`ionos_dbaas_mongodb_replication_lag_seconds`**                     | The delay between the primary and secondary copies of data is measured in seconds. Monitor this metric to spot any slow or unhealthy secondaries early on and ensure read‑consistency, and trigger alerts or scaling actions before replication delays affect application performance or data‑loss risk.                                   |
| **`ionos_dbaas_mongodb_replication_last_election_timestamp_seconds`** | The time when the most recent primary election occurred in the MongoDB replica set, measured in seconds. Monitor this metric to detect unexpected failovers and trigger alerts or investigations before they impact application availability.                                                                                              |

</details>

<details>

<summary><strong>Top Operations (per 5m) Window</strong></summary>

| **Metric**                                    | **Description**                                                                                                                                                                           |
| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`ionos_dbaas_mongodb_top_commands_count`**  | The number of active MongoDB command operations. Monitor this metric to spot workload spikes or long-running queries.                                                                     |
| **`ionos_dbaas_mongodb_top_getmore_count`**   | The number of active `getMore` operations on each MongoDB node. Monitor this metric to detect any heavy cursor-paging workloads.                                                          |
| **`ionos_dbaas_mongodb_top_insert_count`**    | The number of active insert operations on each MongoDB node. Monitor this metric to identify any bulk inserts.                                                                            |
| **`ionos_dbaas_mongodb_top_queries_count`**   | The number of active query operations per MongoDB node. Monitor this metric to identify long-running queries and tune indexes.                                                            |
| **`ionos_dbaas_mongodb_top_readLock_count`**  | The number of active operations that hold a `readLock` on each MongoDB node. Monitor this metric to identify read-heavy operations and optimize query patterns.                           |
| **`ionos_dbaas_mongodb_top_remove_count`**    | The number of active remove or delete operations on each MongoDB node. Monitor this metric to identify workloads that need to be deleted.                                                 |
| **`ionos_dbaas_mongodb_top_total_count`**     | The total number of active operations of all types, such as queries, inserts, updates, deletes, and so on. Monitor this metric to obtain a health snapshot of overall workload intensity. |
| **`ionos_dbaas_mongodb_top_update_count`**    | The number of active update operations on each MongoDB node. Monitor this metric to identify any workloads that are particularly update-heavy.                                            |
| **`ionos_dbaas_mongodb_top_writeLock_count`** | The number of operations holding a write-lock on each MongoDB node. Monitor this metric to detect any write-lock contentions and adjust indexes accordingly.                              |

</details>

## Target audience

This tutorial is intended to help both developers and technical decision-makers.

## What you will learn

By following this tutorial, you will learn how to:

* Access MongoDB cluster metrics using Grafana.
* Understand key MongoDB performance and health metrics.
* Configure Grafana to visualize MongoDB metrics.
* Set up authentication for secure metric access.
* Explore and interpret MongoDB metrics for monitoring and troubleshooting.

## Before you begin

You need to activate the [<mark style="color:blue;">Logging Service</mark>](https://docs.ionos.com/cloud/observability/logging-service) to create the necessary setup to view the Grafana dashboard. To do so, [<mark style="color:blue;">Create a Logging Pipeline</mark>](https://docs.ionos.com/cloud/observability/logging-service/dcd-how-tos/create-logging-service-pipeline). This establishes a successful logging pipeline connection. You can view the created logging pipeline in the **Logging Service** page. For more information, see [<mark style="color:blue;">View Logging Pipelines</mark>](https://docs.ionos.com/cloud/observability/logging-service/dcd-how-tos/view-logging-pipelines).

## Cost considerations

The following resources outlined in this tutorial are billable and will incur costs when used:

* **Storage or retention:** Retaining data for extended periods and using metrics with many distinct label values increases storage usage. For more information, see [<mark style="color:blue;">Prices</mark>](https://docs.ionos.com/cloud/support/general-information/price-list/ionos-cloud-eur-en#ionos-cloud-object-storage).
* **Image or asset hosting for documentation:** At scale, storing and delivering images or assets through a CDN may incur additional costs.
* **Authentication token management:** Token issuance is free; it incurs operational overhead only.

To set up cost alerts and estimate costs based on your traffic, see [<mark style="color:blue;">Cost Alert</mark>](https://docs.ionos.com/cloud/set-up-ionos-cloud/management/usage/cost-alert) and [<mark style="color:blue;">Cost & Usage</mark>](https://docs.ionos.com/cloud/set-up-ionos-cloud/management/usage/cost-and-usage).

## Procedure

Use the following procedure to access the MongoDB metrics using Grafana:

{% stepper %}
{% step %}
**Open Grafana Dashboard**

1\. From the **Logging Service** page, click **Grafana Dashboard**. The URL to the Grafana sign-in page opens in the browser.

![Grafana Dashboard](https://3040852435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEpuEvuLJIyhyeRGhmrv1%2Fuploads%2Fgit-blob-1ee4623b8c6188151cb622258fad2b01dd5d20d7%2Fmongodb-logging-service-grafana.png?alt=media)

2\. Click **Sign in with IONOS** from the Grafana sign-in page.

3\. Use the IONOS Cloud Data Center Designer (DCD) Single Sign-On (SSO) credentials and click **Sign In**.

![DCD SSO](https://3040852435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEpuEvuLJIyhyeRGhmrv1%2Fuploads%2Fgit-blob-83660c414300caff3fb7d1b171b4acc939f432b9%2Fmongodb-grafana-sso.png?alt=media)
{% endstep %}

{% step %}
**Configure the Data Source**

1\. From the Grafana home page, on the left-hand menu, go to **Connections** > **Data sources**.

2\. From the **Data sources** page, select **IONOS Telemetry**.

![IONOS Cloud Telemetry Data Sources](https://3040852435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEpuEvuLJIyhyeRGhmrv1%2Fuploads%2Fgit-blob-96d3141c24cb4c2fa11bf884b327c39053deb180%2Fmongodb-grafana-data-sources.png?alt=media)

3\. In the **Settings** tab, go to the **Authentication** section > **HTTP headers**.

4\. Select **Add header**. You need to add an authorization header with a bearer token. To do so, configure the following:

* **Header:** In this field, enter **Authorization**.
* **Value:** Obtain the bearer token value from the **Token Manager** section in the DCD and prefix `Bearer` before the **Token Value** and add it here. For more information, see [<mark style="color:blue;">Generate authentication token</mark>](https://docs.ionos.com/cloud/set-up-ionos-cloud/management/identity-access-management/token-manager#generate-authentication-token).

5\. In the **Other** section, select the **HTTP method** as `GET`.

![HTTP Method](https://3040852435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEpuEvuLJIyhyeRGhmrv1%2Fuploads%2Fgit-blob-7dbaeea6655716f640053b8be14f69dcb544711e%2Fmongodb-grafana-http-method.png?alt=media)

6\. Click **Save & test**, available at the end of the **Settings** page.
{% endstep %}

{% step %}
**View MongoDB Database Metrics**

1\. From the Grafana home page, on the left-hand menu, go to **Explore** > **Metrics**.

2\. Select **Let's start!** to start metrics exploration and choose **IONOS Telemetry** as the **Data source**.

![Metrics](https://3040852435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEpuEvuLJIyhyeRGhmrv1%2Fuploads%2Fgit-blob-24f51ef14dbde78bfabb31ab0d8eee71624333c7%2Fmongodb-grafana-metrics.png?alt=media)

3\. In the **Search metrics**, type the keywords such as `mongodb` to view metrics related to MongoDB.

![MongoDB metrics](https://3040852435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEpuEvuLJIyhyeRGhmrv1%2Fuploads%2Fgit-blob-70f45344bb8571020421931b73b8ae90d85f4ab3%2Fmongodb-grafana-mongodb-metrics.png?alt=media)
{% endstep %}
{% endstepper %}

### Final result

The metrics for MongoDB clusters are successfully available in the Grafana dashboard. For details on the metrics available, see [<mark style="color:blue;">Metrics for MongoDB</mark>](#metrics-for-mongodb).

## Conclusion

MongoDB cluster metrics are accessible through the Grafana dashboard. This functionality is available when a logging pipeline connection is established and the cluster is active within your contract.

Alternatively, you can deploy and configure their own Grafana instance. In this case, establishing a logging pipeline connection is not required. Instead, you can directly configure the appropriate data sources in Grafana to visualize and monitor MongoDB cluster metrics.
