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.
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.
-
For information about MongoDB roles, see MongoDB built-in roles.
-
For an example of how to configure these permissions, see lpu.sh.
Configure the receiver
Modify your collector configuration file as follows. All examples are for the Splunk Distribution of the OpenTelemetry Collector.
-
In the
receivers:section, addmongodb:YAMLmongodb: hosts: - endpoint: localhost:27017 username: otel password: ${env:MONGODB_PASSWORD} collection_interval: 60s initial_delay: 1s tls: insecure: true insecure_skip_verify: true -
In the
service.pipelines:section, add the receiver to the metrics pipeline:YAMLmetrics: receivers: - mongodb -
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
-
BASH
sudo systemctl restart splunk-otel-collector - Windows
-
Windows with installer script:
BASHstop-service splunk-otel-collector start-service splunk-otel-collector - Kubernetes
-
BASH
helm upgrade your-splunk-otel-collector splunk-otel-collector-chart/splunk-otel-collector -f your-override-values.yamlwhere
splunk-otel-collector-chartis the name you gave to the Helm chart in thehelm repo addcommand.
Advanced configurations
- Configure MongoDB hosts
-
Use the
hostssetting to define a list ofhost:portor Unix domain socket endpoints. The default is[localhost:27017]. Thetransportoption is no longer available.-
For standalone MongoDB deployments, specify the hostname and port of the
mongodinstance. -
For replica sets, specify the hostnames and ports of the
mongodinstances in the replica set configuration. If you setreplica_set, the receiver automatically discovers nodes. -
For sharded MongoDB deployments, specify a list of
mongoshosts.
-
- Monitor a replica set
-
If your MongoDB deployment is a replica set, use
replica_setto specify the replica set name. This setting lets the receiver automatically discover other nodes in the replica set. - Use a direct connection
-
Set
direct_connectiontotrueto prevent the driver from automatically discovering other nodes and to use a direct connection to the host. - Configure TLS
-
Use the
tlssetting 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:
receivers:
samplereceiver:
metrics:
metric-one:
enabled: true
metric-two:
enabled: false
The following is an example of host metrics receiver configuration with activated metrics:
receivers:
hostmetrics:
scrapers:
process:
metrics:
process.cpu.utilization:
enabled: true
-
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).