MongoDB
The MongoDB source collects metrics and logs from MongoDB. Metrics are scraped from one or more mongod endpoints (host:port or a unix domain socket) using the OpenTelemetry MongoDB receiver, optionally authenticating with a monitoring user and TLS. Logs are read from MongoDB log files on the collector host and parsed into structured records.
Supported Telemetry Types
macOS
✓
✓
Linux
✓
✓
Windows
✓
✓
Prerequisites
A reachable MongoDB endpoint. The collector must reach each
mongodhost and port listed in Hosts (defaultlocalhost:27017). For replica sets, list the member hosts; for sharded deployments, list themongoshosts.A monitoring user (metrics). If authentication is enabled, create a least-privilege user with the built-in
clusterMonitorrole and supply it in Username / Password.clusterMonitorgrants the read-only monitoring access the receiver needs without write privileges. See MongoDB Built-In Roles for the role definition and the mongodbreceiver README for an example least-privilege-user setup.TLS material (optional). If MongoDB requires TLS, enable TLS and provide the CA file, and for mutual TLS the client certificate and key files, on the collector host.
Log file read access (logs). The collector must have read access to the MongoDB log files at the configured Log Paths (default
/var/log/mongodb/mongodb.log*and/var/log/mongodb/mongod.log*).
Configuration

General
Choose Telemetry Type
Telemetry Selector
No
["Logs", "Metrics"]
Which telemetry to collect. Valid values: Logs, Metrics.
Logs
Log Paths
Strings
No
/var/log/mongodb/mongodb.log*, /var/log/mongodb/mongod.log*
Path to MongoDB log file(s).
Parse To
Enum: body, attributes
No
body
Parse structured log parts to either body or attributes.
Start At
Enum: beginning, end
No
end
Start reading logs from beginning or end.
Parse
Boolean
No
true
Parses the log fields into structured data.
These parameters apply when Choose Telemetry Type includes Logs. All are advanced settings.
Metrics
Hosts
Strings
No
localhost:27017
List of host:port or unix domain socket endpoints.
Username
String
No
(empty)
If authentication is required, specify a username with clusterMonitor permission. Advanced setting.
Password
String
No
(empty)
The user's password. Sensitive value. Advanced setting.
Collection Interval
Integer
No
60
How often (seconds) to scrape for metrics. Advanced setting.
Filtering
Metrics
No
(empty)
Disable individual MongoDB metrics from collection. Advanced setting.
These parameters apply when Choose Telemetry Type includes Metrics.
TLS (Metrics)
Enable TLS
Boolean
No
false
Whether or not to use TLS. Advanced setting.
Skip TLS Certificate Verification
Boolean
No
false
Enable to skip TLS certificate verification. Relevant when Enable TLS is true.
TLS Certificate Authority File
String
No
(empty)
Certificate authority used to validate TLS certificates. Relevant when Enable TLS is true.
TLS Client Certificate File
String
No
(empty)
A TLS certificate used for client authentication, if mutual TLS is enabled. Relevant when Enable TLS is true.
TLS Client Private Key File
String
No
(empty)
A TLS private key used for client authentication, if mutual TLS is enabled. Relevant when Enable TLS is true.
Examples
Scrape metrics from an authenticated replica set over TLS
Collects metrics every 30 seconds from two mongod members, authenticating with a clusterMonitor user and validating the server certificate against a CA file.
Configuration Tips
For a replica set, list the member
mongodhosts; for a sharded cluster, list themongoshosts instead of individual shards.Use a dedicated user with only the
clusterMonitorrole for metrics. It is read-only and avoids granting write access to the collector.Use Filtering to disable metrics you do not need, reducing cardinality and downstream cost.
Troubleshooting
Metrics endpoint connection refused
Symptoms: no MongoDB metrics arrive; collector logs show connection refused or timeout to the configured host.
Solutions:
Confirm each entry in Hosts is a reachable
mongod(ormongos) host:port from the collector.Verify firewall and network policy allow the collector to reach the MongoDB port (default 27017).
Authentication failed
Symptoms: collector logs report authentication or unauthorized errors during scrape.
Solutions:
Confirm Username and Password are correct and the user exists in MongoDB.
Verify the user has the built-in
clusterMonitorrole. See MongoDB Built-In Roles.
TLS handshake failure
Symptoms: scrape fails with a certificate or TLS handshake error.
Solutions:
Confirm Enable TLS matches the server's requirement and that the TLS Certificate Authority File can validate the server certificate.
For testing only, enable Skip TLS Certificate Verification; do not use this in production.
No logs collected
Symptoms: no log records appear from the source.
Solutions:
Confirm the MongoDB log files exist at the configured Log Paths and that the collector user can read them.
If you expect existing log content, set Start At to
beginning.
Standalone Source
Related Resources
Last updated
Was this helpful?