MongoDB
The OpenTelemetry Collector's MongoDB receiver collects 25+ metrics from MongoDB 4.0+, including operation rates, lock activity, replication throughput, WiredTiger cache reads, and operation latency. This guide configures the receiver, sets up a monitoring user, and ships metrics to base14 Scout.
Prerequisites​
| Requirement | Minimum | Recommended |
|---|---|---|
| MongoDB | 4.0 | 6.0+ |
| OTel Collector Contrib | 0.90.0 | latest |
| base14 Scout | Any | - |
Before starting:
- MongoDB must be accessible from the host running the Collector
- A user with
clusterMonitorrole for monitoring access - OTel Collector installed - see Docker Compose Setup
What You'll Monitor​
- Operations: command, query, insert, update, delete, and getmore rates
- Active workload: concurrent reads, concurrent writes
- Locks: acquire counts, wait times, deadlock counts
- Replication: replication operation rates across all operation types
- Performance: operation latency, page faults, WiredTiger cache reads
- Health: server health status, uptime
Full metric reference: OTel MongoDB Receiver
Access Setup​
Create a dedicated MongoDB user with the clusterMonitor role:
use admin
db.createUser({
user: "${MONGO_USER}",
pwd: "${MONGO_PASSWORD}",
roles: [
{ role: "clusterMonitor", db: "admin" },
]
})
Minimum required permissions:
clusterMonitoronadmin- required forserverStatus,replSetGetStatus, and database statistics- No write permissions are needed
Test connectivity with the monitoring user:
mongosh "mongodb://${MONGO_USER}:${MONGO_PASSWORD}@localhost:27017/"\
"admin?authSource=admin" --eval "db.serverStatus().ok"
Configuration​
receivers:
mongodb:
hosts:
- endpoint: localhost:27017 # Update with your MongoDB host
username: ${env:MONGO_USER}
password: ${env:MONGO_PASSWORD}
collection_interval: 60s
timeout: 10s
# TLS Configuration
tls:
insecure: true
insecure_skip_verify: true
direct_connection: true # false for replica sets
metrics:
# Disabled by default - enable for full observability
mongodb.uptime:
enabled: true
mongodb.active.reads:
enabled: true
mongodb.active.writes:
enabled: true
mongodb.commands.rate:
enabled: true
mongodb.deletes.rate:
enabled: true
mongodb.flushes.rate:
enabled: true
mongodb.getmores.rate:
enabled: true
mongodb.health:
enabled: true
mongodb.inserts.rate:
enabled: true
mongodb.lock.acquire.count:
enabled: true
mongodb.lock.acquire.time:
enabled: true
mongodb.lock.acquire.wait_count:
enabled: true
mongodb.lock.deadlock.count:
enabled: true
mongodb.operation.latency.time:
enabled: true
mongodb.operation.repl.count:
enabled: true
mongodb.page_faults:
enabled: true
mongodb.queries.rate:
enabled: true
mongodb.repl_commands_per_sec:
enabled: true
mongodb.repl_deletes_per_sec:
enabled: true
mongodb.repl_getmores_per_sec:
enabled: true
mongodb.repl_inserts_per_sec:
enabled: true
mongodb.repl_queries_per_sec:
enabled: true
mongodb.repl_updates_per_sec:
enabled: true
mongodb.updates.rate:
enabled: true
mongodb.wtcache.bytes.read:
enabled: true
processors:
resource:
attributes:
- key: environment
value: ${env:ENVIRONMENT}
action: upsert
- key: service.name
value: ${env:SERVICE_NAME}
action: upsert
batch:
timeout: 10s
send_batch_size: 1024
# Export to base14 Scout
exporters:
otlphttp/b14:
endpoint: ${env:OTEL_EXPORTER_OTLP_ENDPOINT}
tls:
insecure_skip_verify: true
service:
pipelines:
metrics:
receivers: [mongodb]
processors: [batch, resource]
exporters: [otlphttp/b14]
Environment Variables​
MONGO_USER=otel_monitor
MONGO_PASSWORD=your_password
ENVIRONMENT=your_environment
SERVICE_NAME=your_service_name
OTEL_EXPORTER_OTLP_ENDPOINT=https://<your-tenant>.base14.io
Verify the Setup​
Start the Collector and check for metrics within 60 seconds:
# Check Collector logs for successful connection
docker logs otel-collector 2>&1 | grep -i "mongodb"
# Verify MongoDB server status
mongosh "mongodb://${MONGO_USER}:${MONGO_PASSWORD}@localhost:27017/"\
"admin?authSource=admin" --eval "db.serverStatus().ok"
Troubleshooting​
Connection refused​
Cause: Collector cannot reach MongoDB at the configured endpoint.
Fix:
- Verify MongoDB is running:
systemctl status mongodordocker ps | grep mongo - Confirm the endpoint address and port (default 27017) in your config
- Check
bindIpinmongod.conf- change to0.0.0.0if the Collector runs on a separate host
Authentication failed​
Cause: Monitoring credentials are incorrect or the user lacks permissions.
Fix:
- Test credentials directly:
mongosh "mongodb://user:pass@localhost:27017/admin" --eval "db.runCommand({ping:1})" - Verify the user has the
clusterMonitorrole:db.getUser("otel_monitor") - Check
MONGO_USERandMONGO_PASSWORDenvironment variables
No metrics appearing in Scout​
Cause: Metrics are collected but not exported.
Fix:
- Check Collector logs for export errors:
docker logs otel-collector - Verify
OTEL_EXPORTER_OTLP_ENDPOINTis set correctly - Confirm the pipeline includes both the receiver and exporter
Replication metrics showing zero​
Cause: MongoDB is running as a standalone instance without a replica set.
Fix:
- Replication metrics (
mongodb.operation.repl.count,mongodb.repl_*_per_sec) require a replica set configuration - On standalone instances, these metrics report zero - this is expected
- Set
direct_connection: falsewhen monitoring a replica set
FAQ​
Does this work with MongoDB running in Kubernetes?
Yes. Set endpoint to the MongoDB service DNS
(e.g., mongodb.default.svc.cluster.local:27017) and inject
credentials via a Kubernetes secret. The Collector can run as a sidecar
or DaemonSet.
How do I monitor a MongoDB replica set?
Set direct_connection: false and point to the primary. Add multiple
receiver blocks for each member if you want per-node metrics:
receivers:
mongodb/primary:
hosts:
- endpoint: mongo-1:27017
direct_connection: true
mongodb/secondary:
hosts:
- endpoint: mongo-2:27017
direct_connection: true
Then include both in the pipeline:
receivers: [mongodb/primary, mongodb/secondary]
What permissions does the monitoring account need?
The clusterMonitor role on the admin database. No write access is
required. The Collector only reads metrics - it does not modify MongoDB
data.
Why are lock deadlock counts always zero?
MongoDB uses optimistic concurrency control with WiredTiger, so deadlocks are rare under normal workloads. Non-zero values indicate contention issues worth investigating.
What's Next?​
- Create Dashboards: Explore pre-built dashboards or build your own. See Create Your First Dashboard
- Monitor More Components: Add monitoring for PostgreSQL, MySQL, and other components
- Fine-tune Collection: Adjust
collection_intervalbased on your database workload
Related Guides​
- OTel Collector Configuration — Advanced collector configuration
- Docker Compose Setup — Run the Collector locally
- PostgreSQL Monitoring - Alternative database monitoring
- CouchDB Monitoring - Alternative document database monitoring