MongoDB receiver

The MongoDB receiver collects metrics from a MongoDB instance.

The MongoDB receiver is a component of the OpenTelemetry Collector. It connects to standalone MongoDB clusters, including non-Atlas managed MongoDB servers, and supports metrics pipelines.

The receiver collects metrics with the MongoDB dbStats and serverStatus commands and uses the Go MongoDB driver. For more information, see the MongoDB Go driver documentation.

Note: Use the MongoDB receiver in place of the deprecated SignalFx Smart Agent mongodb monitor type.

Supported versions and platforms

The MongoDB receiver supports these MongoDB versions and platforms:

  • Versions: 4.0 and higher, including 5.0, 6.0, and 7.0
  • Platforms: Standalone MongoDB clusters, including non-Atlas managed MongoDB servers

Prerequisites

Prepare MongoDB by creating a least-privilege user with the clusterMonitor role to collect metrics.

Note: If you're using automatic discovery with MongoDB, see Automatic discovery for MongoDB.

Configure the receiver

Modify your collector configuration file as follows. All examples are for the Splunk Distribution of the OpenTelemetry Collector.

  1. In the receivers: section, add mongodb:

    YAML
    mongodb:
      hosts:
        - endpoint: localhost:27017
      username: otel
      password: ${env:MONGODB_PASSWORD}
      collection_interval: 60s
      initial_delay: 1s
      tls:
        insecure: true
        insecure_skip_verify: true
  2. In the service.pipelines: section, add the receiver to the metrics pipeline:

    YAML
    metrics:
      receivers:
        - mongodb
  3. Restart the collector to apply your configuration changes.

    The restart command varies depending on what platform you deployed the collector on and what tool you used to deploy it. Here are general examples of the restart command:

    Linux

    Linux with installer script:

    BASH
    sudo systemctl restart splunk-otel-collector
    Windows

    Windows with installer script:

    BASH
    stop-service splunk-otel-collector
    start-service splunk-otel-collector
    Kubernetes

    Kubernetes with Helm:

    BASH
    helm upgrade your-splunk-otel-collector splunk-otel-collector-chart/splunk-otel-collector -f your-override-values.yaml

    where splunk-otel-collector-chart is the name you gave to the Helm chart in the helm repo add command.

Advanced configurations

Configure MongoDB hosts

Use the hosts setting to define a list of host:port or Unix domain socket endpoints. The default is [localhost:27017]. The transport option is no longer available.

  • For standalone MongoDB deployments, specify the hostname and port of the mongod instance.

  • For replica sets, specify the hostnames and ports of the mongod instances in the replica set configuration. If you set replica_set, the receiver automatically discovers nodes.

  • For sharded MongoDB deployments, specify a list of mongos hosts.

Monitor a replica set

If your MongoDB deployment is a replica set, use replica_set to specify the replica set name. This setting lets the receiver automatically discover other nodes in the replica set.

Use a direct connection

Set direct_connection to true to prevent the driver from automatically discovering other nodes and to use a direct connection to the host.

Configure TLS

Use the tls setting to configure TLS. By default, insecure settings are rejected and certificate verification is active. For more information, see TLS configuration settings.

Settings reference

Configuration options for this receiver:

included

https://raw.githubusercontent.com/splunk/collector-config-tools/main/cfg-metadata/receiver/mongodb.yaml

Metrics reference

Metrics, attributes, and resource attributes reported by this receiver:

included

https://raw.githubusercontent.com/splunk/collector-config-tools/main/metric-metadata/mongodbreceiver.yaml

mongodb.extent.count is available for versions earlier than 4.4 with the mmapv1 storage engine.

Activate or deactivate specific metrics

You can activate or deactivate specific metrics by setting the enabled field in the metrics section for each metric. For example:

YAML
receivers:
  samplereceiver:
    metrics:
      metric-one:
        enabled: true
      metric-two:
        enabled: false

The following is an example of host metrics receiver configuration with activated metrics:

YAML
receivers:
  hostmetrics:
    scrapers:
      process:
        metrics:
          process.cpu.utilization:
            enabled: true
Note: Deactivated metrics aren’t sent to Splunk Observability Cloud.
Billing
  • If you’re in a MTS-based subscription, all metrics count towards metrics usage.

  • If you’re in a host-based plan, metrics listed as active (Active: Yes) on this document are considered default and are included free of charge.

Learn more at Infrastructure Monitoring subscription usage (Host and metric plans).