Supported telemetry types
The MongoDB integration supports these telemetry types:Prerequisites
The MongoDB integration has the following prerequisites:-
Run MongoDB 6.0 or greater. To find the version of a server, run
db.version()inmongosh. -
Create a monitoring user in MongoDB for the CXDOT Collector. Connect to the server with
mongoshas a user that can create users. On a replica set, connect to the primary. Grant the monitoring user theclusterMonitorrole on theadmindatabase and thereadrole on thelocaldatabase:Replacecxdotwith the username for your environment. TheclusterMonitorrole grants read-only access to server, replication, and database statistics. Thereadrole onlocallets the Collector read the replication operations log. -
On a sharded cluster, create the monitoring user in two places. Create it through a
mongosrouter, which stores the user on the config servers, so that the Collector can authenticate to eachmongosand each config server member. Then create the same user on each shard’s replica set by connecting directly to that shard’s primary. The Collector connects directly to each shard member, and a direct connection authenticates against the shard’s own shard-local users. -
Make port
27017, or your custom MongoDB port, reachable from the CXDOT Collector.
Configure
The MongoDB integration is enabled by default and collects from pods and Services that carry autodiscovery annotations for MongoDB. For more information, see autodiscovery. The integration supports standalone servers, replica sets, and sharded clusters. Each server is a target of its own: everymongod, including each replica set member, shard
member, and config server member, and every mongos router. The Collector connects
directly to each target and reports that server’s own metrics.
Some metrics come only from servers in certain roles:
- Storage statistics for each database come from a standalone server, from the primary of
a replica set that isn’t part of a sharded cluster, and from each
mongosrouter. Other replica set members, shard members, and config server members report these statistics for theirlocaldatabase only. - Connection pool metrics come from each
mongosrouter and from each shard member and config server member. - The logical session count comes from each
mongosrouter. - Replication metrics come from replica set members.
-
Add autodiscovery annotations to every pod that runs a
mongodor amongos. The annotations supply each target’s endpoint and the monitoring user’s credentials. Metrics from discovered pods arrive with that pod’s Kubernetes metadata attached. -
Optional: Configure static targets, for example MongoDB servers outside your
Kubernetes cluster, instead of discovered targets. List every server as its own
entry. One elected replica of the cluster-tier CXDOT Collector collects from static
targets, so provide the password to that tier through a Kubernetes Secret. For more
information, see
architecture.
To add the
mongodb.cluster.nameattribute to every metric from a target, set that entry’scluster_name. For example, add the following to the Helm values file for your CXDOT Collector:When you configure static targets, this integration instance collects from exactly those targets and stops collecting from discovered targets. -
Optional: Collect from discovered targets and static targets at the same time by
configuring a second instance of the integration. For example, add the following to
the Helm values file for your CXDOT Collector:
The
mongodbkey is the default instance, which collects from discovered targets. Themongodb/statickey defines a named instance that collects from the static targets and reads its password from theMONGODB_PASSWORDenvironment variable that the previous step defines. Keep themongodbkey: after you configure any MongoDB instance, the CXDOT Collector runs only the instances that you configure. -
Optional: Collect additional metric groups. By default, the integration collects none
of them. These settings apply to static targets. Discovered targets take the matching
settings from their autodiscovery annotations. For example, add the settings to the
mongodb/staticinstance from the previous step in the Helm values file for your CXDOT Collector:The groups differ in what they cost your servers:metrics.commandsandtcmallocread the server status the Collector already reads at every collection interval, so they add no load.topruns onetopcommand on everymongodthat isn’t an arbiter at every collection interval. For each collection the server has run an operation on since it started, it produces a count and a time series for each operation type, and a count and a time series for each kind of lock access.collectionruns on a standalone server, on the primary of a replica set that isn’t part of a sharded cluster, and on everymongosrouter you configure as a target. Each router reports the statistics of every collection in the sharded cluster, so enable the group on an instance that lists one router, or the Collector reads the same statistics once per router and reports each collection once per router. It runs everycollection_stats.intervaland reads each collection’s statistics with one aggregation per collection. Setcollection_stats.databasesandcollection_stats.collectionsto limit which databases and collections it reads. Whencollection_stats.collectionsis empty, the Collector lists the collections of each database and reads at mostcollection_stats.max_collections_per_databaseof them.
-
Optional: Collect index access counts. The integration doesn’t collect them by default,
because collecting them adds load on a server with many collections: at every
collection interval, the Collector lists the collections of each database and reads
the index statistics of each collection. This setting applies to static targets.
Discovered targets take it from their autodiscovery annotations. For example, add the
setting to the
mongodb/staticinstance in the Helm values file for your CXDOT Collector: -
Optional: Collect the CPU usage of the
mongodandmongosprocesses. The MongoDB integration doesn’t report it. Enable per-process metrics in the Host integration on the nodes that run your servers. For example, add the following to the Helm values file for your CXDOT Collector: -
Optional: Disable the integration. For example, add the following to the Helm values
file for your CXDOT Collector:
Validate
To validate the MongoDB integration, follow these steps:-
In the
Live Telemetry Analyzer,
add the following filters:
__name__=cxdot.integration.target.healthcxdot.integration.name=mongodb
1, identified by itsserver.addressandserver.portattributes. A value of0means that the CXDOT Collector couldn’t connect to the target or authenticate to it, for example because the server rejected the monitoring user’s credentials. -
In
Metrics Explorer,
run the following query while clients send operations to the MongoDB servers:
Confirm that the query returns a value greater than
0for each target.
Troubleshooting
- Replication metrics are missing: MongoDB reports these metrics only on
replica set members, so a standalone server doesn’t produce them. On a replica set
member, confirm that the monitoring user holds the
readrole on thelocaldatabase, which the operations log metrics require. - Storage statistics are missing for some databases: The Collector reads these statistics for at most 100 databases on each server. Only the servers in the roles that the Configure section lists report them for your databases.
- A shard member reports
0forcxdot.integration.target.health: The monitoring user exists only on the config servers. Create it on the shard’s replica set, as described in the prerequisites. - An arbiter reports
0forcxdot.integration.target.healthand no other metrics: An arbiter keeps no users, so it rejects connections that authenticate. Configure the arbiter’s target without credentials, for example in a separate integration instance that sets nousername.
Configuration reference
Configure one MongoDB integration instance with the following settings. In Helm values, place these settings underconfig.integrations.mongodb. In a Collector configuration file, place
them under cxdot.integrations.mongodb.
Optional settings
-
enabledType:boolean. Optional. Default:true. Whether to run the MongoDB integration. If true, the Collector collects MongoDB metrics. If false, the Collector doesn’t run this integration. -
usernameType:string. Optional. Default: empty string. MongoDB username for connections to statically configured targets. Setusernameandpasswordtogether. The Collector authenticates whenusernameorauth_mechanismis set. Otherwise, it connects without authenticating. -
passwordType:string. Optional. MongoDB password for connections to statically configured targets. Setusernameandpasswordtogether. The Collector masks this value in diagnostic output, logs, and errors. -
auth_sourceType:string. Optional. Default:admin. Database that holds the credentials for statically configured targets. -
auth_mechanismType:string. Optional. Default: empty string. Authentication mechanism for statically configured targets. When empty, the Collector negotiates a SCRAM mechanism with the server. Allowed values: empty string,SCRAM-SHA-1,SCRAM-SHA-256,MONGODB-X509,MONGODB-AWS,GSSAPI,PLAIN. -
schemeType:string. Optional. Default:mongodb. Connection string scheme for statically configured targets. Withmongodb+srv, each instance’sendpointis a DNS name, without a port, whose DNS service record lists the servers to connect to, anddirect_connectionmust be false. Allowed values:mongodb,mongodb+srv. -
replica_setType:string. Optional. Default: empty string. Replica set name that statically configured targets must belong to. When empty, the Collector doesn’t verify the replica set name. -
direct_connectionType:boolean. Optional. Default:true. If true, connects to each target as a single server, without discovering the rest of its replica set, so each replica set member reports its own metrics. If false, the connection follows the replica set topology, and the Collector reads replication operation counts from each secondary over a connection without TLS, so a replica set that requires TLS reports the primary’s counts instead. Must be false whenschemeismongodb+srv. -
collection_intervalType:duration. Optional. Default:15s. Time between metric collections from each statically configured MongoDB target. -
timeoutType:duration. Optional. Default:15s. Maximum time to wait when connecting to each statically configured MongoDB target and for each metric collection from it. -
collect_index_statsType:boolean. Optional. Default:false. Whether to collectmongodb.index.access.count, the number of index accesses for each collection, summed over the collection’s indexes. If true, at every collection interval the Collector lists the collections of every database exceptlocaland reads the index statistics of every collection, on every target. This adds load in proportion to the number of collections on the server. If false, the Collector doesn’t list collections or read index statistics. Applies to statically configured targets. Targets discovered through annotations use the setting in their annotations instead. When their annotations turn it on, the Collector reads every collection of every database exceptlocalon those targets, regardless of which databases and collections the annotations name. -
additional_metricsType:array of string. Optional. Default:[]. Optional metric groups to collect in addition to the default metrics. By default, no group is collected. Themetrics.commandsgroup counts how many times the server ran thecount,createIndexes,delete,findAndModify,insert, andupdatecommands, split by whether each run succeeded or failed, asmongodb.command.count. Thetcmallocgroup reports memory allocator readings, such as the bytes allocated, the heap size, and the free bytes the allocator holds, as themongodb.tcmalloc.*metrics. Thetopgroup counts how many operations of each kind ran on each collection and the time they took, asmongodb.collection.operation.countandmongodb.collection.operation.time, and the same split by whether each operation held a read or a write lock, asmongodb.collection.access.countandmongodb.collection.access.time. It’s collected from everymongodthat isn’t an arbiter, for every collection the server has run an operation on since it started. Thecollectiongroup reports each collection’s storage statistics, operation latencies, and full collection scans, such asmongodb.collection.data.size,mongodb.collection.operation.latency.time, andmongodb.collection.scan.count. It’s collected from a standalone server, from the primary of a replica set that isn’t part of a sharded cluster, and from everymongosrouter configured as a target. Each router reports every collection in the sharded cluster, with each shard’s statistics separately, so list one router in an instance that enables the group to read them once. It’s collected everycollection_stats.interval, for the databases and collections thatcollection_statsselects.metrics.commandsandtcmallocread the server status the Collector already reads at every collection interval, so they add no load on the server.topruns onetopcommand at every collection interval.collectionruns onelistCollectionscommand per database, unlesscollection_stats.collectionsnames the collections, and one$collStatsaggregation per collection, at everycollection_stats.interval. Applies to statically configured targets. Targets discovered through annotations use the setting in their annotations instead. -
collection_statsType:object. Optional. Settings for thecollectiongroup ofadditional_metrics: which databases and collections it reads, how many collections per database, and how often. Applies to statically configured targets. Targets discovered through annotations take the matching settings from their annotations instead. -
collection_stats.databasesType:array of string. Optional. Default:[]. Databases whose collections thecollectiongroup reads. When empty, the Collector reads every database on the target, up to 100. On targets discovered through annotations, the group reads every database when the annotations turn on database autodiscovery, and otherwise only the database the annotations name,adminby default. -
collection_stats.collectionsType:array of string. Optional. Default:[]. Collections thecollectiongroup reads in each database. When empty, the Collector reads every collection the monitoring user is authorized to list in each database, up tomax_collections_per_database. On targets discovered through annotations, the collections the annotations name apply only while database autodiscovery is off. -
collection_stats.max_collections_per_databaseType:integer. Optional. Default:100. Minimum:1. Maximum number of collections thecollectiongroup reads in each database whencollectionsis empty. Targets discovered through annotations use the setting in their annotations instead. -
collection_stats.intervalType:duration. Optional. Default:5m. Time between reads of thecollectiongroup. Each read costs one$collStatsaggregation per collection, so it runs less often thancollection_intervalby default. When it’s no longer thancollection_interval, the group is read at every collection interval. A read that doesn’t finish withintimeoutstops there, and the next read continues from where it stopped. Targets discovered through annotations use the setting in their annotations instead. -
instancesType:array of object. Optional. Default:[]. Static MongoDB targets. When this list isn’t empty, this integration instance collects from exactly these targets and stops discovering targets through autodiscovery annotations. -
instances[].endpointType:string. Required. Network address of the MongoDB server inhost:portformat, for example,mongodb.default.svc:27017. With themongodb+srvscheme, a DNS name without a port. -
instances[].cluster_nameType:string. Optional. Name of the MongoDB cluster the target belongs to. When set, the Collector adds it as themongodb.cluster.nameresource attribute to every metric from this target. When unset, metrics from this target don’t carry the attribute. Targets discovered through annotations use the cluster name in their annotations. -
tlsType:object. Optional. Default:{"insecure":true}. TLS settings for connections to statically configured MongoDB targets. By default, the connection is unencrypted. The Collector connects with TLS wheninsecureis false or whenca_fileorca_pemis set, and verifies the server certificate unlessinsecure_skip_verifyis true. The default applies only when you set notlsoption: if you set any, also setinsecure: trueto keep the connection unencrypted. With themongodb+srvscheme, the Collector always connects with TLS, and wheninsecureis true and no certificate authority is set it verifies the server certificate against the system certificate authorities. -
tls.ca_fileType:string. Optional. Path to a PEM-encoded certificate authority (CA) certificate file used to verify the MongoDB server certificate. Setting it enables TLS even wheninsecureis true. If omitted, the Collector uses the system certificate authority pool. -
tls.ca_pemType:string. Optional. PEM-encoded certificate authority certificate content used to verify the MongoDB server certificate. Setting it enables TLS even wheninsecureis true. -
tls.cert_fileType:string. Optional. Path to the PEM-encoded client certificate file to present when the MongoDB server requires mutual TLS orMONGODB-X509authentication. -
tls.cert_pemType:string. Optional. PEM-encoded client certificate content to present when the MongoDB server requires mutual TLS orMONGODB-X509authentication. -
tls.cipher_suitesType:array of string. Optional. TLS cipher suites that the Collector can use, in preference order. If omitted, the Collector uses the secure defaults from the Go TLS library. For supported names, see https://go.dev/src/crypto/tls/cipher_suites.go. -
tls.curve_preferencesType:array of string. Optional. Elliptic curves that the Collector can use for an elliptic curve Diffie-Hellman ephemeral handshake, in preference order. If omitted, the Collector uses the Go TLS library defaults. -
tls.include_system_ca_certs_poolType:boolean. Optional. Whether to also trust the system certificate authority pool whenca_fileorca_pemis set. If true, the Collector trusts both sources. If false, it trusts only the configured certificate authorities. With neitherca_filenorca_pemset, the Collector always uses the system pool. -
tls.insecureType:boolean. Optional. Whether to disable transport security. If true, the Collector uses an unencrypted connection unlessca_fileorca_pemis set. If false, the Collector connects with TLS. -
tls.insecure_skip_verifyType:boolean. Optional. Whether to skip verification of the MongoDB server certificate. If true, the connection is encrypted but isn’t authenticated and is vulnerable to man-in-the-middle attacks. If false, the Collector verifies the certificate. -
tls.key_fileType:string. Optional. Path to the PEM-encoded client private key file used withcert_filefor mutual TLS orMONGODB-X509authentication. -
tls.key_pemType:string. Optional. PEM-encoded client private key content used withcert_pemfor mutual TLS orMONGODB-X509authentication. -
tls.max_versionType:string. Optional. Maximum TLS protocol version the Collector can use, such as1.3. If omitted, the Collector uses the maximum version supported by the Go TLS library. -
tls.min_versionType:string. Optional. Minimum TLS protocol version the Collector can use, such as1.2. If omitted, the minimum version is TLS 1.2. -
tls.reload_intervalType:duration. Optional. How often the Collector reloads certificate and key files. If omitted, the Collector doesn’t reload the files. -
tls.server_name_overrideType:string. Optional. Server name to verify in the MongoDB server certificate instead of the endpoint hostname. Use this setting when the certificate name differs from the endpoint hostname. -
tls.tpmType:object. Optional. Trusted platform module settings for the TLS private key. -
tls.tpm.authType:string. Optional. Authorization value for the trusted platform module key. -
tls.tpm.enabledType:boolean. Optional. Whether to use a trusted platform module for the TLS private key. If true, the Collector loads the key from the configured device or socket. If false, the Collector uses the configured key file or in-memory key. -
tls.tpm.owner_authType:string. Optional. Owner authorization value for the trusted platform module. -
tls.tpm.pathType:string. Optional. Path to the trusted platform module device or Unix domain socket, such as/dev/tpm0or/dev/tpmrm0.