Skip to content

MongoDB

The MongoDB integration collects server statistics with the collector’s mongodb receiver and parses MongoDB’s structured JSON log. Connecting it adds the Mongo overview dashboard. In the app the integration is called Mongo.

Use this page when you run MongoDB yourself, standalone, as a replica set or sharded.

  • MongoDB 4.4 or newer. Check with db.version().
  • An otelcol-contrib collector, v0.88.0 or newer, where you can add config files and environment variables. See Integrations.
  • For metrics: a least-privilege user with the clusterMonitor role, and network access from the collector to MongoDB.
  • For logs: the collector can read the MongoDB log file. The systemLog.path setting in mongod.conf shows where it is.

Create the monitoring user:

use admin
db.createUser({
user: "monitoring",
pwd: "<password>",
roles: ["clusterMonitor"]
});
mongodb-metrics.yaml
receivers:
mongodb:
# Standalone: the mongod. Replica set: its members (others are discovered
# when replica_set is set). Sharded: the mongos hosts.
hosts:
- endpoint: ${env:MONGODB_ENDPOINT}
username: ${env:MONGODB_USERNAME}
password: ${env:MONGODB_PASSWORD}
collection_interval: 60s
tls:
insecure: true
insecure_skip_verify: true
# ca_file: /etc/ssl/certs/ca-certificates.crt
# cert_file: /etc/ssl/certs/mongodb.crt
# key_file: /etc/ssl/certs/mongodb.key
metrics:
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
processors:
# Adds host.name. Remove when the collector runs on another host.
resourcedetection/system:
detectors: ["system"]
system:
hostname_sources: ["os"]
exporters:
otlp/fusescope:
endpoint: ${env:OTLP_DESTINATION_ENDPOINT}
tls:
insecure: true
service:
pipelines:
metrics/mongodb:
receivers: [mongodb]
processors: [resourcedetection/system]
exporters: [otlp/fusescope]
Variable Example Description
MONGODB_ENDPOINT localhost:27017 MongoDB host:port, reachable from the collector.
MONGODB_USERNAME monitoring Monitoring user.
MONGODB_PASSWORD Its password.
OTLP_DESTINATION_ENDPOINT fusescope-collector.example.com:4317 FuseScope collector, OTLP gRPC.

When MongoDB uses TLS, set insecure: false in the receiver’s tls block and fill in the certificate files.

Run the collector with --config mongodb-metrics.yaml --config mongodb-logs.yaml, as shown in Run the collector. Set insecure: false in the exporter when the FuseScope endpoint uses TLS.

  1. Open Integrations › Mongo.
  2. Click Connect Mongo, then I have already configured.
  3. Click Test Connection. The badge reads This integration is working properly once logs with source = mongodb or MongoDB metrics arrive. Until then it reads Listening for data….

Mongo overview dashboard, with a host.name variable:

  • Operations count, Total operations time
  • Read latency, Write latency, Command latency
  • Cache operations
  • Network IO

No log pipelines and no alert rules. Parsing happens in the collector config; see Log pipelines for more.

Field Path Type
Timestamp timestamp timestamp
Severity Text severity_text string
Severity Number severity_number number
MongoDB Component attributes.component string
Source attributes.source (mongodb) string

The fields of each entry’s attr object are flattened into attributes as well.

Metric Type Unit Description
mongodb_operation_count Sum number Operations executed.
mongodb_operation_time Sum ms Total time spent on operations.
mongodb_operation_latency_time Gauge us Operation latency.
mongodb_operation_repl_count Sum number Replicated operations executed.
mongodb_document_operation_count Sum number Document operations executed.
mongodb_cache_operations Sum number Cache operations.
mongodb_connection_count Sum number Connections.
mongodb_session_count Sum number Active sessions.
mongodb_cursor_count Sum number Open cursors.
mongodb_cursor_timeout_count Sum number Cursors that timed out.
mongodb_network_io_receive Sum Bytes Bytes received.
mongodb_network_io_transmit Sum Bytes Bytes transmitted.
mongodb_network_request_count Sum number Requests received.
mongodb_memory_usage Sum Bytes Memory used.
mongodb_global_lock_time Sum ms Time the global lock was held.
mongodb_lock_acquire_count Sum number Lock acquisitions per mode.
mongodb_lock_acquire_wait_count Sum number Lock acquisitions that had to wait.
mongodb_lock_acquire_time Sum microseconds Cumulative lock wait time.
mongodb_lock_deadlock_count Sum number Lock acquisitions that hit a deadlock.
mongodb_database_count Sum number Databases.
mongodb_collection_count Sum number Collections.
mongodb_object_count Sum number Objects.
mongodb_data_size Sum Bytes Uncompressed collection size.
mongodb_storage_size Sum Bytes Storage allocated to collections.
mongodb_index_count Sum number Indexes.
mongodb_index_size Sum Bytes Space allocated to indexes.
mongodb_index_access_count Sum number Index accesses.
mongodb_extent_count Sum number Extents.
mongodb_health Gauge number Server health status.
mongodb_uptime Sum ms Time the server has been running.