MongoDB receiver
The MongoDB receiver collects data from a MongoDB instance.
The MongoDB receiver is a component of the OpenTelemetry Collector. It connects to standalone or self-managed MongoDB clusters, including non-Atlas managed MongoDB servers, and MongoDB Atlas deployments, and supports metrics and logs pipelines.
Use the MongoDB receiver for Splunk Database Monitoring with self-managed MongoDB and MongoDB Atlas deployments. For MongoDB Atlas, configure the MongoDB receiver with scheme: mongodb+srv. The MongoDB Atlas receiver, mongodb_atlas, doesn't support the db.server.query_sample and db.server.top_query events that Splunk Database Monitoring uses.
The receiver collects metrics with the MongoDB dbStats and serverStatus commands and can collect query sample and top query events. The receiver uses the Go MongoDB driver. For more information, see the MongoDB Go driver documentation.
mongodb monitor type.
MongoDB and MongoDB Atlas support starts from these minimum collector versions:
- Splunk Distribution of the OpenTelemetry Collector (
splunk-otel-collector) v0.158.0 or higher - Community (OSS) version of the OpenTelemetry Collector (
opentelemetry-collector-contrib) v0.158.0 or higher
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
Splunk Database Monitoring supports these MongoDB versions and platforms for collection of query sample and top query events:
- Versions: Standalone or self-managed MongoDB 7.0
- Platforms: MongoDB Atlas dedicated clusters M10 and higher
Prerequisites
-
Create a monitoring user for the receiver:
Prepare MongoDB by creating a dedicated user with the
clusterMonitorrole 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.Note: If you're using automatic discovery with MongoDB for metrics-only collection, see Automatic discovery for MongoDB.- Self-managed MongoDB
-
Create a dedicated MongoDB user for the OpenTelemetry Collector in the
admindatabase. Grant the user these roles:clusterMonitoronadminreadAnyDatabaseonadmin
Create an additional custom role that grants
findandindexStatsaccess onsystem.profile:JSuse admin db.createUser({ user: "otel-user", pwd: "otel-user-password", roles: [ { role: "clusterMonitor", db: "admin" }, { role: "readAnyDatabase", db: "admin" } ] }) db.createRole({ role: "otelSystemProfileIndexStats", privileges: [ { resource: { db: "", collection: "system.profile" }, actions: [ "find", "indexStats" ] } ], roles: [] }) db.grantRolesToUser("otel-user", [ { role: "otelSystemProfileIndexStats", db: "admin" } ]) - MongoDB Atlas
-
Create a database user for the OpenTelemetry Collector. To use the Atlas CLI, set the Atlas project ID and create the user:
BASHexport ATLAS_PROJECT_ID='atlas-project-id' atlas dbusers create \ --username 'otel-user' \ --password 'otel-user-password' \ --role clusterMonitor@admin,readAnyDatabase@admin \ --projectId "$ATLAS_PROJECT_ID"If the user already exists, update it:
BASHatlas dbusers update 'otel-user' \ --authDB admin \ --role clusterMonitor@admin,readAnyDatabase@admin \ --projectId "$ATLAS_PROJECT_ID"Verify the user:
BASHatlas dbusers describe 'otel-user' \ --projectId "$ATLAS_PROJECT_ID" \ -o jsonTo use MongoDB Atlas, create or update the database user in the MongoDB Atlas UI:
- Log in to MongoDB Atlas.
- Select the correct organization and project.
- Select .
- Select Add New Database User for a new user, or select Edit for an existing user.
- Select Password authentication and enter the username and password for the OpenTelemetry Collector user.
- Assign
clusterMonitoronadminandreadAnyDatabaseonadmin. - Save the user.
-
Configure the database:
- Self-managed MongoDB
-
To improve
top_queryreliability, configure profiling level1and a slow query threshold of100 ms. MongoDB records operations that run longer than the slow query threshold as slow operations. The receiver can use those records for top query collection.If you use
docker-compose, add these options to themongodcommand:YAMLcommand: [ "mongod", "--replSet", "rs0", "--bind_ip_all", "--port", "27017", "--auth", "--keyFile", "/etc/mongo-keyfile", "--profile", "1", "--slowms", "100" ]If you use
mongod.conf, add these settings:YAMLoperationProfiling: mode: slowOp slowOpThresholdMs: 100Restart MongoDB and validate the profiling settings:
JSdb.getSiblingDB("database-name").getProfilingStatus() - MongoDB Atlas
-
Since MongoDB Atlas profiler settings don't persist (they're reset to default values after reboot), the receiver uses a fallback mechanism to get logs.
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:- Self-managed MongoDB
-
YAML
mongodb/receiver-instance-name: collection_interval: 10s hosts: - endpoint: host-ip:27017 username: otel-user password: otel-user-password auth_source: admin direct_connection: true events: db.server.query_sample: enabled: true db.server.top_query: enabled: true tls: insecure: true insecure_skip_verify: true - MongoDB Atlas
-
YAML
mongodb/atlas-receiver-instance-name: scheme: mongodb+srv hosts: - endpoint: host-domain-name username: otel-user password: otel-user-password auth_source: admin collection_interval: 10s events: db.server.query_sample: enabled: true db.server.top_query: enabled: true - Non-Database Monitoring
-
YAML
mongodb: hosts: - endpoint: localhost:27017 username: otel password: ${env:MONGODB_PASSWORD} initial_delay: 1s tls: insecure: true insecure_skip_verify: true
Important:If you're using the Splunk Distribution of OpenTelemetry Collector, leave the following receiver settings at their default values:
-
query_sample_collection.max_rows_per_query(Default: 100) top_query_collection.collection_interval(Default: 60s)-
top_query_collection.max_query_sample_count(Default: 1000)
These values support Database Monitoring without affecting the performance of the database or the collector. If you increase these values, you might adversely affect the performance of your database or collector, and this could result in ingest throttling.
-
In the
exporters:section, add an instance of the OTLP/HTTP exporter namedotlp_http/dbmon. Confirm that asignalfxexporter is already present in your configuration because themetrics/dbmonpipeline uses it.Note: If you deployed the Splunk Distribution of the OpenTelemetry Collector, thesignalfxexporter is already present in the default configuration.YAMLotlp_http/dbmon: headers: X-SF-Token: your-splunk-access-token X-splunk-instrumentation-library: dbmon logs_endpoint: https://ingest.your-splunk-realm.observability.splunkcloud.com/v3/event sending_queue: batch: flush_timeout: 15s max_size: 10485760 sizer: bytes -
In the
service.pipelines:section, create a metrics pipeline namedmetrics/dbmonand a logs pipeline namedlogs/dbmon. Replacemongodb/receiver-instance-namewith the receiver instance name you configured, such asmongodb/nodeormongodb/atlas:YAMLmetrics/dbmon: receivers: - mongodb/receiver-instance-name processors: - memory_limiter - batch exporters: - signalfx logs/dbmon: receivers: - mongodb/receiver-instance-name processors: - memory_limiter - batch exporters: - otlp_http/dbmonImportant: Use an identical list of processors for themetricsandlogs/dbmonpipelines, and include these processors in the same order. -
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.
Your database instance should now be visible on as well as on if you have a Database Monitoring license. For troubleshooting, see Troubleshoot data collection .
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. -
For MongoDB Atlas deployments that use SRV DNS, set
schemetomongodb+srvand specify one host.
-
- 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. - Identify database instances uniquely
-
Use
service.instance.id,service.name, andservice.namespaceresource attributes to distinguish MongoDB instances when the generated identifier doesn't identify each instance uniquely in your deployment.To identify database instances by using a combination of
service.name,service.namespace, andoverride_value, use Splunk Distribution of the OpenTelemetry Collector (splunk-otel-collector) version 0.158.0 or higher or Community (OSS) version of the OpenTelemetry Collector (opentelemetry-collector-contrib) version 0.158.0 or higher.If you collect metrics and logs, add the resource attributes under both
metrics.resource_attributesandlogs.resource_attributes. For example:YAMLmongodb/node: hosts: - endpoint: host-ip:27017 username: otel-user password: otel-user-password metrics: resource_attributes: service.instance.id: enabled: true override_value: host-ip:27017 service.name: enabled: true override_value: payments-db service.namespace: enabled: true override_value: prod-us-east-k8s logs: resource_attributes: service.instance.id: enabled: true override_value: host-ip:27017 service.name: enabled: true override_value: payments-db service.namespace: enabled: true override_value: prod-us-east-k8sNote: Setoverride_valueonly whenenabled: true. When enabled withoutoverride_value,service.namedefaults tounknown_service:mongodbandservice.namespacedefaults to an empty string. - 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. - Enable optional metrics
-
Set
metrics.metric-name.enabledtotrue. For example:YAMLmongodb: metrics: mongodb.health: enabled: true
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).