---
title: MongoDB Metrics
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > OpenTelemetry in Datadog > Integrations > MongoDB Metrics
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# MongoDB Metrics

## Overview{% #overview %}

{% image
   source="https://docs.dd-static.net/images/opentelemetry/collector_exporter/mongodb_metrics.5b1dcd3fb30c298ab37696cf01feaeb4.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/opentelemetry/collector_exporter/mongodb_metrics.5b1dcd3fb30c298ab37696cf01feaeb4.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="The MongoDB - Overview dashboard, showing tiles for averaged uptime, healthy replica set members, and shard, primary, secondary, and config server counts." /%}

The [MongoDB receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/mongodbreceiver) collects MongoDB metrics that populate the [MongoDB - Overview](https://app.datadoghq.com/dash/integration/13/mongodb---overview) dashboard and MongoDB monitors. Configure the receiver according to the specifications of the latest version of the `mongodbreceiver`.

For more information, see the OpenTelemetry project documentation for the [MongoDB receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/mongodbreceiver).

## Setup{% #setup %}

To collect MongoDB metrics with OpenTelemetry for use with Datadog:

1. Create a MongoDB user with the [`clusterMonitor` role](https://www.mongodb.com/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterMonitor).
1. Configure one [MongoDB receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/mongodbreceiver) for each `mongod` and `mongos` instance in your OpenTelemetry Collector configuration.
1. Configure the processors that convert the receiver's network and page fault counters to per-second rates.
1. Add the service pipelines to your Collector configuration.
1. Set up the OpenTelemetry Collector with the [recommended configuration](https://docs.datadoghq.com/opentelemetry/setup/collector_exporter.md), which exports to Datadog with the OTLP HTTP exporter (`otlp_http`).

### MongoDB user{% #mongodb-user %}

Run this command in `mongosh`:

```javascript
db.getSiblingDB("admin").createUser({
  user: "<USERNAME>",
  pwd: "<PASSWORD>",
  roles: [{ role: "clusterMonitor", db: "admin" }]
})
```

### MongoDB receiver{% #mongodb-receiver %}

```yaml
receivers:
  mongodb/mongodb-node-1:
    hosts:
      - endpoint: "<HOST>:<PORT>"
    username: "<USERNAME>"
    password: "<PASSWORD>"
    direct_connection: true
    tls:
      insecure: true
    collection_interval: 10s
    metrics:
      mongodb.operation.latency.time:
        enabled: true
      mongodb.commands.rate:
        enabled: true
      mongodb.deletes.rate:
        enabled: true
      mongodb.getmores.rate:
        enabled: true
      mongodb.inserts.rate:
        enabled: true
      mongodb.queries.rate:
        enabled: true
      mongodb.updates.rate:
        enabled: true
      mongodb.page_faults:
        enabled: true

processors:
  transform/mongodb-node-1:
    metric_statements:
      - context: metric
        statements:
          - set(metric.is_monotonic, true) where metric.name == "mongodb.network.io.receive"
          - set(metric.is_monotonic, true) where metric.name == "mongodb.network.io.transmit"
  cumulativetodelta/mongodb-node-1:
    initial_value: drop
    include:
      match_type: strict
      metrics:
        - mongodb.network.io.receive
        - mongodb.network.io.transmit
        - mongodb.page_faults
  deltatorate/mongodb-node-1:
    metrics:
      - mongodb.network.io.receive
      - mongodb.network.io.transmit
      - mongodb.page_faults
```

If your MongoDB server uses TLS, remove `tls.insecure` and configure the receiver's TLS settings.

See the [MongoDB receiver documentation](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/mongodbreceiver) for detailed configuration options and requirements.

### Service pipelines{% #service-pipelines %}

Add this pipeline under `service.pipelines` in your Collector configuration. The `otlp_http` exporter comes from the [recommended configuration](https://docs.datadoghq.com/opentelemetry/setup/collector_exporter.md).

```yaml
service:
  pipelines:
    metrics/mongodb-node-1:
      receivers: [mongodb/mongodb-node-1]
      processors: [transform/mongodb-node-1, cumulativetodelta/mongodb-node-1, deltatorate/mongodb-node-1]
      exporters: [otlp_http]
```

## Data collected{% #data-collected %}

| OTEL                           | DESCRIPTION                                   | FILTER                                     |
| ------------------------------ | --------------------------------------------- | ------------------------------------------ |
| mongodb.commands.rate          | The number of commands executed per second.   |
| mongodb.connection.count       | The number of connections.                    | `db.namespace`: `admin``type`: `available` |
| mongodb.connection.count       | The number of connections.                    | `db.namespace`: `admin``type`: `current`   |
| mongodb.deletes.rate           | The number of deletes executed per second.    |
| mongodb.getmores.rate          | The number of getmores executed per second.   |
| mongodb.inserts.rate           | The number of insertions executed per second. |
| mongodb.memory.usage           | The amount of memory used.                    | `db.namespace`: `admin``type`: `resident`  |
| mongodb.network.io.receive     | The number of bytes received.                 |
| mongodb.network.io.transmit    | The number of by transmitted.                 |
| mongodb.operation.latency.time | The latency of operations.                    | `operation`: `command`                     |
| mongodb.operation.latency.time | The latency of operations.                    | `operation`: `read`                        |
| mongodb.operation.latency.time | The latency of operations.                    | `operation`: `write`                       |
| mongodb.page_faults            | The number of page faults.                    |
| mongodb.queries.rate           | The number of queries executed per second.    |
| mongodb.updates.rate           | The number of updates executed per second.    |

The receiver's `db.namespace` attribute maps to the Datadog `db` tag.

For the full mapping between OpenTelemetry and Datadog metric names, see [OpenTelemetry Metrics Mapping](https://docs.datadoghq.com/opentelemetry/mapping/metrics_mapping.md).

### Known limitations{% #known-limitations %}

- OpenTelemetry series have no `replset_name` or `clustername` tag. Dashboard widgets and monitors grouped by these tags show OpenTelemetry data in a single untagged group.
- `mongodb.uptime` is not mapped. The receiver reports it in milliseconds, and the Agent reports it in seconds under the same metric name.
- `mongodb.stats.datasize` is not mapped. The receiver runs `dbStats` on every node, while the Agent runs it only on standalone, `mongos`, or unsharded primary nodes.
- These Datadog metrics have no MongoDB receiver equivalent:
  - `mongodb.chunks.jumbo`
  - `mongodb.chunks.total`
  - `mongodb.globallock.currentqueue.readers`
  - `mongodb.globallock.currentqueue.writers`
  - `mongodb.oplog.logsizemb`
  - `mongodb.oplog.timediff`
  - `mongodb.oplog.usedsizemb`
  - `mongodb.replset.health`
  - `mongodb.replset.optime_lag`
  - `mongodb.sessions.count`
  - `mongodb.stats.fstotalsize`
  - `mongodb.stats.fsusedsize`

## Further reading{% #further-reading %}

Additional helpful documentation, links, and articles:

- [Setting Up the OpenTelemetry Collector](https://docs.datadoghq.com/opentelemetry/setup/collector_exporter.md)
