Mongodb Receiver
contrib
Maintainers: @justinianvoss22, @dyl10s, @ishleenk17
Source: opentelemetry-collector-contrib
Supported Telemetry
Overview
Purpose
The purpose of this receiver is to allow users to monitor metrics from standalone MongoDB clusters. This includes non-Atlas managed MongoDB Servers.Prerequisites
This receiver supports MongoDB versions:- 4.0+
- 5.0
- 6.0
- 7.0
clusterMonitor role in order to collect metrics. Please refer to lpu.sh for an example of how to configure these permissions.
Configuration
The following settings are optional:hosts(default: [localhost:27017]): list ofhost:portor unix domain socket endpoints.Thetransportoption is no longer available.- For standalone MongoDB deployments this is the hostname and port of the mongod instance
- For replica sets specify the hostnames and ports of the mongod instances that are in the replica set configuration. If the
replica_setfield is specified, nodes will be autodiscovered. - For a sharded MongoDB deployment, please specify a list of the
mongoshosts.
scheme(default:mongodb): connection scheme. Usemongodb+srvfor clusters that use SRV DNS records (e.g. MongoDB Atlas). When usingmongodb+srv, exactly one host must be specified.username: If authentication is required, the user can withclusterMonitorpermissions can be provided here.password: If authentication is required, the password can be provided here.auth_mechanism: (optional) The authentication mechanism to use. Common values includeSCRAM-SHA-1,SCRAM-SHA-256,MONGODB-X509,GSSAPI,MONGODB-AWS, etc. If not specified, MongoDB will use the default mechanism.auth_source: (optional) The database name to use for authentication. If not specified, MongoDB will use the default authentication database (usuallyadmin).auth_mechanism_properties: (optional) A map of key-value pairs specifying additional properties for the authentication mechanism. For example, when usingGSSAPI(Kerberos), you may need to setSERVICE_NAME. ForMONGODB-AWS, you may need to setAWS_SESSION_TOKENwhen using temporary AWS credentials.collection_interval: (default =1m): This receiver collects metrics on an interval. This value must be a string readable by Golang’s time.ParseDuration. Valid time units arens,us(orµs),ms,s,m,h.initial_delay(default =1s): defines how long this receiver waits before starting.replica_set: If the deployment of MongoDB is a replica set then this allows users to specify the replica set name which allows for autodiscovery of other nodes in the replica set.timeout: (default =1m) The timeout of running commands against mongo.tls: TLS control. By default, insecure settings are rejected and certificate verification is on.direct_connection: If true, then the driver will not try to autodiscover other nodes, and perform instead a direct connection o the host.
Example Configuration
Example Configuration (MongoDB Atlas / SRV)
Authentication
The receiver supports several MongoDB authentication mechanisms. Theauth_mechanism, auth_source, and auth_mechanism_properties fields are passed directly to the MongoDB Go driver’s options.Credential struct.
SCRAM (Default)
SCRAM-SHA-256 is the default authentication mechanism for MongoDB 4.0+. Ifauth_mechanism is not specified and username/password are provided, the driver will negotiate the strongest SCRAM mechanism supported by the server (SCRAM-SHA-256, falling back to SCRAM-SHA-1).
X.509 Certificate Authentication
X.509 authentication uses TLS client certificates instead of username and password. The certificate’s subject DN is used as the identity.tlsCertificateKeyFile) containing both the certificate and private key. However, the receiver uses the OpenTelemetry Collector’s standard TLS configuration, which requires separate cert_file and key_file entries.
If you have a combined PEM file, split it into separate files:
MONGODB-AWS (IAM Authentication)
MONGODB-AWS authenticates using AWS IAM credentials. This mechanism is available in MongoDB 4.4+ and requires server-side support (e.g., MongoDB Atlas or Percona Server for MongoDB). It is not supported by the MongoDB Community Edition. Using explicit IAM credentials:username, password, and auth_mechanism_properties can be omitted:
GSSAPI (Kerberos)
GSSAPI/Kerberos is available for MongoDB Enterprise deployments only. It is not supported by MongoDB Community Edition. Using this mechanism requires:- The collector to be compiled with the
gssapibuild tag and cgo support (CGO_ENABLED=1). - On Linux, the
libkrb5library must be installed.
Note: The defaultotelcontribcolbinary is built without thegssapibuild tag and withCGO_ENABLED=0, so GSSAPI authentication will not work out of the box. You will need to build a custom collector withCGO_ENABLED=1and thegssapibuild tag to use this mechanism.
mongodb. Users can authenticate with an explicit password or by storing authentication keys in keytab files initialized with the kinit utility.
Metrics
The following metric are available with versions:mongodb.extent.count< 4.4 with mmapv1 storage engine
Feature gate configurations
See the Collector feature gates for an overview of feature gates in the collector. STABLE:receiver.mongodb.removeDatabaseAttr
The feature gate receiver.mongodb.removeDatabaseAttr will remove the database name attribute from data points
because it is already found on the resource. This feature gate cannot be changed and will be removed soon.
Metrics
| Metric Name | Description | Unit | Type | Attributes |
|---|---|---|---|---|
❌ mongodb.active.reads | The number of read operations currently being processed. | {reads} | UpDownCounter | |
❌ mongodb.active.writes | The number of write operations currently being processed. | {writes} | UpDownCounter | |
✅ mongodb.cache.operations | The number of cache operations of the instance. | {operations} | Counter | type |
✅ mongodb.collection.count | The number of collections. | {collections} | UpDownCounter | db.namespace |
❌ mongodb.commands.rate | The number of commands executed per second. | {command}/s | Gauge | |
✅ mongodb.connection.count | The number of connections. | {connections} | UpDownCounter | connection_type, db.namespace |
✅ mongodb.cursor.count | The number of open cursors maintained for clients. | {cursors} | UpDownCounter | |
✅ mongodb.cursor.timeout.count | The number of cursors that have timed out. | {cursors} | UpDownCounter | |
✅ mongodb.data.size | The size of the collection. Data compression does not affect this value. | By | UpDownCounter | db.namespace |
✅ mongodb.database.count | The number of existing databases. | {databases} | UpDownCounter | |
❌ mongodb.deletes.rate | The number of deletes executed per second. | {delete}/s | Gauge | |
✅ mongodb.document.operation.count | The number of document operations executed. | {documents} | UpDownCounter | operation, db.namespace |
✅ mongodb.extent.count | The number of extents. | {extents} | UpDownCounter | db.namespace |
❌ mongodb.flushes.rate | The number of flushes executed per second. | {flush}/s | Gauge | |
❌ mongodb.getmores.rate | The number of getmores executed per second. | {getmore}/s | Gauge | |
✅ mongodb.global_lock.time | The time the global lock has been held. | ms | Counter | |
❌ mongodb.health | The health status of the server. | 1 | Gauge | |
✅ mongodb.index.access.count | The number of times an index has been accessed. | {accesses} | UpDownCounter | collection, db.namespace |
✅ mongodb.index.count | The number of indexes. | {indexes} | UpDownCounter | db.namespace |
✅ mongodb.index.size | Sum of the space allocated to all indexes in the database, including free index space. | By | UpDownCounter | db.namespace |
❌ mongodb.inserts.rate | The number of insertions executed per second. | {insert}/s | Gauge | |
❌ mongodb.lock.acquire.count | Number of times the lock was acquired in the specified mode. | {count} | Counter | lock_type, lock_mode, db.namespace |
❌ mongodb.lock.acquire.time | Cumulative wait time for the lock acquisitions. | microseconds | Counter | lock_type, lock_mode, db.namespace |
❌ mongodb.lock.acquire.wait_count | Number of times the lock acquisitions encountered waits because the locks were held in a conflicting mode. | {count} | Counter | lock_type, lock_mode, db.namespace |
❌ mongodb.lock.deadlock.count | Number of times the lock acquisitions encountered deadlocks. | {count} | Counter | lock_type, lock_mode, db.namespace |
✅ mongodb.memory.usage | The amount of memory used. | By | UpDownCounter | memory_type, db.namespace |
✅ mongodb.network.io.receive | The number of bytes received. | By | UpDownCounter | |
✅ mongodb.network.io.transmit | The number of by transmitted. | By | UpDownCounter | |
✅ mongodb.network.request.count | The number of requests received by the server. | {requests} | UpDownCounter | |
✅ mongodb.object.count | The number of objects. | {objects} | UpDownCounter | db.namespace |
✅ mongodb.operation.count | The number of operations executed. | {operations} | Counter | operation |
❌ mongodb.operation.latency.time | The latency of operations. | us | Gauge | operation_latency |
❌ mongodb.operation.repl.count | The number of replicated operations executed. | {operations} | Counter | operation |
✅ mongodb.operation.time | The total time spent performing operations. | ms | Counter | operation |
❌ mongodb.page_faults | The number of page faults. | {faults} | Counter | |
❌ mongodb.queries.rate | The number of queries executed per second. | {query}/s | Gauge | |
❌ mongodb.repl_commands_per_sec | The number of replicated commands executed per second. | {command}/s | Gauge | |
❌ mongodb.repl_deletes_per_sec | The number of replicated deletes executed per second. | {delete}/s | Gauge | |
❌ mongodb.repl_getmores_per_sec | The number of replicated getmores executed per second. | {getmore}/s | Gauge | |
❌ mongodb.repl_inserts_per_sec | The number of replicated insertions executed per second. | {insert}/s | Gauge | |
❌ mongodb.repl_queries_per_sec | The number of replicated queries executed per second. | {query}/s | Gauge | |
❌ mongodb.repl_updates_per_sec | The number of replicated updates executed per second. | {update}/s | Gauge | |
✅ mongodb.session.count | The total number of active sessions. | {sessions} | UpDownCounter | |
✅ mongodb.storage.size | The total amount of storage allocated to this collection. | By | Counter | db.namespace |
❌ mongodb.updates.rate | The number of updates executed per second. | {update}/s | Gauge | |
❌ mongodb.uptime | The amount of time that the server has been running. | ms | Counter | |
❌ mongodb.wtcache.bytes.read | The number of bytes read into the WiredTiger cache. | By | Counter |
Attributes
| Attribute Name | Description | Type | Values |
|---|---|---|---|
collection | The name of a collection. | string | |
type | The status of the connection. | string | active, available, current |
db.namespace | The name of a database. | string | |
lock_mode | The mode of Lock which denotes the degree of access | string | shared, exclusive, intent_shared, intent_exclusive |
lock_type | The Resource over which the Lock controls access | string | parallel_batch_write_mode, replication_state_transition, global, database, collection, mutex, metadata, oplog |
type | The type of memory used. | string | resident, virtual |
operation | The MongoDB operation being counted. | string | insert, query, update, delete, getmore, command |
operation | The MongoDB operation with regards to latency | string | read, write, command |
type | The result of a cache request. | string | hit, miss |
Resource Attributes
| Attribute Name | Description | Type | Enabled |
|---|---|---|---|
server.address | The address of the MongoDB host. | string | ✅ |
server.port | The port of the MongoDB host. | int | ❌ |
service.instance.id | A unique identifier of the MongoDB resource as a UUID v5, derived from server address and port. | string | ✅ |
Configuration
Example Configuration
Last generated: 2026-04-13