Monitor MongoDB with OpenTelemetry
Osuite monitors MongoDB through the OpenTelemetry Collector’s mongodb receiver, which reads server and database statistics and exports them over OTLP. Connection counts, cache behavior, and lock time arrive with the same resource attributes as your services, so query latency in APM correlates with the database serving it.
Prerequisites
Section titled “Prerequisites”- A reachable MongoDB deployment (4.0 or later).
- A least-privilege user with the built-in
clusterMonitorrole.
Create the monitoring user in the admin database:
db.getSiblingDB("admin").createUser({ user: "otel", pwd: "a-strong-password", roles: [{ role: "clusterMonitor", db: "admin" }]})Export the password to the Collector’s environment:
export MONGODB_PASSWORD='a-strong-password'Configure the Collector
Section titled “Configure the Collector”-
Add the
mongodbreceiver, theotlp/osuiteexporter, and a metrics pipeline. Thehostsfield is a list — add one entry per member to monitor a replica set. Pick the tab that matches where your Collector runs.receivers:mongodb:hosts:- endpoint: localhost:27017username: otelpassword: ${env:MONGODB_PASSWORD}collection_interval: 60stls:insecure: trueprocessors:batch:resourcedetection:exporters:otlp/osuite:endpoint: ingest.<region>.osuite.io:443headers:x-osuite-ingest-token: <your-ingest-token>service:pipelines:metrics:receivers: [mongodb]processors: [batch, resourcedetection]exporters: [otlp/osuite]receivers:mongodb:hosts:- endpoint: mongodb:27017username: otelpassword: ${env:MONGODB_PASSWORD}collection_interval: 60stls:insecure: trueprocessors:batch:resourcedetection:exporters:otlp/osuite:endpoint: ingest.<region>.osuite.io:443headers:x-osuite-ingest-token: <your-ingest-token>service:pipelines:metrics:receivers: [mongodb]processors: [batch, resourcedetection]exporters: [otlp/osuite]receivers:mongodb:hosts:- endpoint: mongodb.default.svc.cluster.local:27017username: otelpassword: ${env:MONGODB_PASSWORD}collection_interval: 60stls:insecure: trueprocessors:batch:resourcedetection:exporters:otlp/osuite:endpoint: ingest.<region>.osuite.io:443headers:x-osuite-ingest-token: <your-ingest-token>service:pipelines:metrics:receivers: [mongodb]processors: [batch, resourcedetection]exporters: [otlp/osuite] -
Start the Collector. On Docker and Kubernetes, the Collector and MongoDB must share a network so the
endpointresolves.
Validate
Section titled “Validate”What you should see
Metrics named mongodb.* appear in Dashboards → Explore metrics within a minute, tagged with the host or pod the Collector runs on.
Data collected
Section titled “Data collected”| Metric | Description | Unit |
|---|---|---|
mongodb.connection.count | Connections by type (active, available, current) | {connections} |
mongodb.cache.operations | Cache hits and misses | {operations} |
mongodb.operation.count* | Operations by type (insert, query, update, delete) | {operations} |
mongodb.document.operation.count | Document operations by type | {documents} |
mongodb.cursor.count | Open cursors held for clients | {cursors} |
mongodb.global_lock.time | Time the global lock has been held | ms |
mongodb.data.size | Uncompressed data size | By |
mongodb.collection.count | Collections per database | {collections} |
mongodb.database.count | Number of databases | {databases} |
mongodb.index.access.count | Times an index has been accessed | {accesses} |
*mongodb.operation.count reports server-wide operation rates; the receiver exposes many more per-database and per-collection metrics through optional toggles.
Dashboards and alerts
Section titled “Dashboards and alerts”Once metrics arrive, build a MongoDB dashboard in the dashboard builder from the series above. Alerts in Osuite are PromQL-based — see Alerts. Useful starting conditions: connection saturation (mongodb.connection.count), a falling cache hit ratio (mongodb.cache.operations), and rising mongodb.global_lock.time.
Troubleshooting
Section titled “Troubleshooting”- Authentication failed — confirm the
oteluser was created in theadmindatabase and that the Collector authenticates againstadmin(the receiver’s default auth source). - Missing metrics — a user without
clusterMonitorcan connect but cannot read server statistics; confirm the role grant.
No data in Osuite after a few minutes? Work through these checks.
- Endpoint — confirm the exporter targets exactly
ingest.<region>.osuite.io:443for your region, over TLS. - Token — confirm the ingest header carries a valid
<your-ingest-token>and has not been rotated. - Pipeline — confirm the signal you expect (traces, logs, or metrics) is wired into an active pipeline with the
otlp/osuiteexporter attached. - Export errors — check the application or Collector logs for OTLP export failures (auth, DNS, TLS, connection refused).
- Network — confirm the host has outbound access to the ingest endpoint on port
443. - Timing — allow up to a minute for the first data to appear before assuming a failure.
Still stuck? Ask the Investigation Agent or contact support.