MongoDB
Overview Copied
The MongoDB Collection Agent plugin gathers operational data from MongoDB. It supports both standalone and replica set topologies.
The plugin enables you to:
- Monitor built-in metrics such as server performance, replica set health, and connection pool statistics.
- Define custom metrics from MongoDB command responses in addition to the built-in metrics.
- Track lock acquisition, contention, and deadlocks.
- Detect assertion failures and other server-level warning signals.
- Monitor active user sessions per MongoDB user.
- Use Kerberos (GSSAPI) authentication where password-based authentication is not permitted.
Prerequisites Copied
Ensure your MongoDB deployment version is supported for this plugin. Refer to Database support for the list of supported versions.
Geneos environment Copied
- Gateway and Netprobe 7.1.x or higher.
- Collection Agent 5.x or higher. To run a Collection Agent, see Collection Agent setup.
Connectivity Copied
If the plugin runs on a different machine from the MongoDB server, ensure there is network connectivity between the two.
Permissions Copied
A MongoDB user account with read monitoring permissions is required. It is recommended to use the built-in clusterMonitor role, especially when connecting to a MongoDB Replica Set.
Configure Geneos to deploy the MongoDB plugin Copied
Setting up this plugin in Geneos involves these primary steps:
-
Configure your other Dynamic Entities in the Gateway. See Create Dynamic Entities in Collection Agent setup for a more detailed procedure.
Set up your Collection Agent plugin Copied
Set up your collector in the Gateway Setup Editor by adding the following configuration in Dynamic Entities > Collectors. For more information, see Collectors in Dynamic Entities.
Configuration reference Copied
collectors:
- name: mongodb
type: plugin
className: MongoDbCollector
# How often to collect metrics, in milliseconds. (optional, default: 300000)
collectionInterval: 300000
# Connection details
connection:
# The connection string in URI format. (required)
# Refer below for the Standard and SRV connection format.
# mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
# mongodb+srv://[username:password@]host[/[defaultauthdb][?options]]
uri: mongodb://localhost:27017/admin
# The alias that will be used to represent the connection string URI. (required)
name: MyConnectionName
# The list of Database names that will be monitored. (optional)
# If this is not defined, then the defaultauthdb in the connection URI will be monitored.
# If defaultauthdb is also not defined, then ALL databases will be monitored.
databaseNames:
- admin
- local
# Connect to a MongoDB instance using TLS
# (optional, default is connecting without tls)
tls:
# The path to a CA PEM file that contains the CA certificate. (optional)
# If this is not specified, the MongoDB Plugin will use the default Java truststore.
caFile: <path to CA PEM file>
# The path to a Client certificate. (optional)
# The mongod/mongos does not require a certificate key file from the client to verify the client's identity.
# If mongod/mongos is configured with Client Certificate Validation, clientCert and clientKey must be supplied.
clientCert: <path to Client Certificate>
# The path to a Client Key PEM File. It should be in PKCS#8 format. (optional)
clientKey: <path to Client Key PEM file>
# Kerberos (GSSAPI) authentication (optional).
# Only applicable when the URI includes authMechanism=GSSAPI and authSource=$external.
# Omit this block entirely when the JVM already has a valid ticket cache (via kinit).
kerberos:
# Path to a keytab file for the principal. (optional)
# When set, the plugin performs a programmatic JAAS login so that authentication
# works without a prior kinit. The principal is read from the URI.
keytabPath: /path/to/mongouser.keytab
# Custom metrics extracted from MongoDB command responses (optional).
# Each group maps to a specific command: serverStatus, dbStats, connPoolStats,
# or replicaSetMember (from replSetGetStatus).
customMetrics:
serverStatus:
- datapointName: server_network_bytesIn
type: counter
path: network.bytesIn
dbStats:
- datapointName: db_total_size
type: gauge
unit: bytes
path: totalSize
connPoolStats:
- datapointName: connpool_acquisition_wait_total_count
type: counter
path: acquisitionWaitTimes.totalCount
replicaSetMember:
- datapointName: rs_member_uptime
type: gauge
unit: seconds
path: uptime
Both the connection uri and name are required.
Sample URIs Copied
Replica set (explicit hosts):
uri: mongodb://user:password@mongo1:27017,mongo2:27018,mongo3:27019/myDb?replicaSet=myReplicaSet
Replica set (SRV):
uri: mongodb+srv://replicaset.srv.com/myDb?replicaSet=myReplicaSet
Standalone server (SRV):
uri: mongodb+srv://user:password@standalone.srv.com/myDb
Standalone server (direct):
uri: mongodb://user:password@localhost:27027/myDb
For more information on the connection URI format, refer to the MongoDB connection string documentation.
Kerberos (GSSAPI) authentication Copied
MongoDB Enterprise supports Kerberos (GSSAPI) authentication. To use Kerberos authentication, set authMechanism=GSSAPI and authSource=$external in the connection URI, and URL-encode the principal name (@ becomes %40).
Example:
uri: mongodb://mongouser%40MONGODB.LOCAL@mongodb.example.local:27017/?authSource=$external&authMechanism=GSSAPI
For more information, refer to the MongoDB Kerberos (GSSAPI) authentication guide.
The optional kerberos block in the connection configuration is only required when you want to supply a keytab file.
If the Collection Agent JVM already has a valid Kerberos ticket cache obtained through kinit, omit the kerberos block.
JVM system properties Copied
When the plugin detects GSSAPI in the connection URI, it may automatically set the following JVM system property at client creation time:
| Property | Value | Condition |
|---|---|---|
javax.security.auth.useSubjectCredsOnly |
false |
Applied only when GSSAPI is configured in the URI, no keytabPath is configured, and the property is not already set |
To enforce subject-only credentials JVM-wide, set the following property on the Collection Agent JVM:
-Djavax.security.auth.useSubjectCredsOnly=true
The plugin honors this setting and does not override it.
No external JAAS configuration file is required. When keytabPath is set, the plugin performs a programmatic JAAS login using Krb5LoginModule and the configured keytab file. The plugin extracts the principal from the connection URI.
Kerberos configuration file lookup Copied
The JDK Kerberos stack locates krb5.conf file in the following order:
-Djava.security.krb5.conf=<path>set on the Collection Agent JVM (recommended for non-default locations)- JDK fallback:
<java.home>/conf/security/krb5.conf - OS default location:
- Linux and macOS —
/etc/krb5.conf - Windows —
%WINDIR%\krb5.ini
Note
The Kerberos configuration file is JVM-global. All GSSAPI-authenticated MongoDB collectors running under the same Netprobe must share the samekrb5.confconfiguration.
Custom metrics Copied
The customMetrics block enables you to extract additional datapoints from MongoDB command responses beyond the built-in set. Each entry under a group is appended to the metrics collected by that command.
Supported groups Copied
| Group | MongoDB command | Scope |
|---|---|---|
serverStatus |
serverStatus |
Per server host |
dbStats |
dbStats |
Per database |
connPoolStats |
connPoolStats |
Per server host |
replicaSetMember |
replSetGetStatus |
Per replica set member. Paths are relative to each member object, not the top-level response. |
Entry fields Copied
Each entry in a group requires the following fields:
| Field | Required | Description |
|---|---|---|
datapointName |
Yes | Name of the published datapoint. Must be unique across all groups. |
type |
Yes | Datapoint type: counter, gauge, attribute, or status. |
path |
Yes | Dot-notation path into the BSON command response (for example, opcounters.insert). |
unit |
No | Unit for gauge metrics only (for example, bytes, seconds). Not for other types. |
Behavior Copied
- If a
datapointNamematches a built-in metric, the custom entry overrides the built-in metric and a warning is logged. - If the
pathdoes not resolve in the command response during collection, an error is logged. Verify the path against the raw command output. - Duplicate
datapointNamevalues across all groups are rejected at startup with a validation error.
Configure your mappings Copied
You can configure your dynamic mappings using a built-in or custom mapping in Dynamic Entities > Mapping.
- To use a built-in mapping, set Option to Built in, then select MongoDB V4 in the Built in > Name field.
- To use a custom mapping, set Option to Custom.
For more information, see Mapping and mapping group in Dynamic Entities.
Connection behavior Copied
Standalone vs replica set mode Copied
The plugin automatically determines its operating mode from the connection URI:
- If the URI contains the
replicaSetoption (for example,?replicaSet=myReplicaSet), the plugin runs in replica set mode. In this mode, it uses a cluster-level client fordbStatscollection and connects to each host individually forserverStatuscollection. - If the URI does not contain a
replicaSetoption, the plugin runs in standalone mode. It collects bothserverStatusanddbStatsfrom each discovered server host.
Database discovery Copied
When databaseNames is not configured, the plugin discovers which databases to monitor using the following fallback chain:
- It lists all available databases on the connected MongoDB instance.
- If the database list is not yet available at startup, it uses the default authentication database specified in the connection URI.
- If no default authentication database is specified in the URI, it uses the
authSourceof the connection credentials. - If none of the above yields a database, it defaults to
admin.
The full database list is refreshed at the next collection interval.
Connecting to a MongoDB Replica Set Copied
To connect to a MongoDB Replica Set, include the replicaSet option in the URI. You can specify one or more replica set hosts.
uri: mongodb://user:password@mongo1:27017,mongo2:27018,mongo3:27019/myDb?replicaSet=myReplicaSet
The clusterMonitor role is recommended, as it provides the necessary permissions for both serverStatus and replSetGetStatus commands across all hosts.
TLS connections Copied
For TLS-enabled MongoDB servers, add the tls section to your connection configuration. The client key must be in PKCS#8 format. See Convert a client key file to PKCS#8 format for conversion instructions.
Published metrics Copied
The plugin collects metrics using four MongoDB commands: serverStatus, dbStats, connPoolStats, and replSetGetStatus. It also runs an aggregation pipeline on the config.system.sessions collection.
Dimensions Copied
All metrics are published with the following dimensions:
| Dimension | Description |
|---|---|
connection_name |
The logical alias for the connection, set by the name configuration field. |
process |
The MongoDB process type on the server (for example, mongod or mongos). |
server |
Server host and port (for standalone and per-host server status metrics). |
replica_set |
Name of the replica set (for replica set and database statistics metrics). |
database_name |
Name of the database (for database statistics metrics). |
lock_type |
Type of lock (for lock metrics). |
member_name |
Name of the replica set member (for replica set member metrics). |
user |
MongoDB username for user session metrics. |
Not all dimensions are present on every metric. Each metric section below lists the specific dimensions it carries.
Server status metrics Copied
The following metrics are collected from the serverStatus command and are published once per monitored server host.
Server instance information metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_instance_version |
attribute | connection_name, process, server |
MongoDB server version string. | |
server_instance_pid |
attribute | connection_name, process, server |
Process ID of the MongoDB server. | |
server_instance_uptime |
gauge | seconds | connection_name, process, server |
Time the server has been running. |
server_instance_uptimeMs |
gauge | milliseconds | connection_name, process, server |
Time the server has been running, in milliseconds. |
server_instance_uptimeEstimate |
gauge | seconds | connection_name, process, server |
Server uptime estimated from the number of calls to gettimeofday. |
server_instance_localTime |
attribute | connection_name, process, server |
Server local time in RFC 1123 format. | |
server_instance_storageEngine |
attribute | connection_name, process, server |
Storage engine in use (for example, wiredTiger). |
Server operation counters metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_opcounters_insert |
counter | connection_name, process, server |
Number of insert operations. | |
server_opcounters_query |
counter | connection_name, process, server |
Number of query operations. | |
server_opcounters_update |
counter | connection_name, process, server |
Number of update operations. | |
server_opcounters_getmore |
counter | connection_name, process, server |
Number of getmore operations. | |
server_opcounters_activeClients_readers |
counter | connection_name, process, server |
Number of active client read operations. | |
server_opcounters_activeClients_writers |
counter | connection_name, process, server |
Number of active client write operations. |
Server memory metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_mem_virtual |
gauge | mebibytes | connection_name, process, server |
Virtual memory used by the MongoDB process. |
server_mem_resident |
gauge | mebibytes | connection_name, process, server |
Resident (physical) memory used by the MongoDB process. |
server_mem_page_faults |
counter | connection_name, process, server |
Number of page faults encountered by the server. |
Server cursor metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_cursors_OpenNoTimeout |
counter | connection_name, process, server |
Number of open cursors with the noTimeout option set. |
|
server_cursors_OpenTotal |
counter | connection_name, process, server |
Total number of open cursors. | |
server_cursors_timedOut |
counter | connection_name, process, server |
Cumulative number of cursors that have timed out. |
Server asserts metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_asserts_msg |
counter | connection_name, process, server |
Number of message assertions raised. | |
server_asserts_regular |
counter | connection_name, process, server |
Number of regular assertions raised. | |
server_asserts_user |
counter | connection_name, process, server |
Number of user assertions raised. | |
server_asserts_warning |
counter | connection_name, process, server |
Number of warning assertions raised. |
Server concurrent transactions metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_concurrent_transactions_read_out |
counter | connection_name, process, server |
Number of read tickets currently in use. | |
server_concurrent_transactions_read_available |
counter | connection_name, process, server |
Number of read tickets currently available. | |
server_concurrent_transactions_read_totalTickets |
counter | connection_name, process, server |
Total number of read tickets configured. | |
server_concurrent_transactions_write_out |
counter | connection_name, process, server |
Number of write tickets currently in use. | |
server_concurrent_transactions_write_available |
counter | connection_name, process, server |
Number of write tickets currently available. | |
server_concurrent_transactions_write_totalTickets |
counter | connection_name, process, server |
Total number of write tickets configured. |
Server connections metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_connections_current |
gauge | connection_name, process, server |
Number of active client connections to the server. | |
server_connections_available |
gauge | connection_name, process, server |
Number of available incoming connections the server can accept. | |
server_connections_rejected |
counter | connection_name, process, server |
Cumulative number of incoming connections rejected by the server. |
Server global lock queue metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_globalLock_currentQueue_total |
gauge | connection_name, process, server |
Total number of operations queued to acquire a lock. | |
server_globalLock_currentQueue_readers |
gauge | connection_name, process, server |
Number of read operations queued to acquire a lock. | |
server_globalLock_currentQueue_writers |
gauge | connection_name, process, server |
Number of write operations queued to acquire a lock. |
Server network metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_network_numSlowSSLOperations |
counter | connection_name, process, server |
Cumulative number of SSL operations that took longer than expected. |
Server transactions metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_transactions_currentInactive |
gauge | connection_name, process, server |
Number of multi-document transactions in an inactive state. |
Server security metrics Copied
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
server_security_sslCertExpirationDate |
attribute | connection_name, process, server |
Expiration date of the server SSL certificate. |
Server lock metrics Copied
Lock metrics are published for each combination of lock type and lock mode. If a lock type is not present in the server response, all its counters are published as zero.
Lock types Copied
ParallelBatchWriterModeReplicationStateTransitionGlobalDatabaseCollectionMutexMetadataoplog
Lock modes Copied
| Mode label | MongoDB key | Description |
|---|---|---|
intent_shared_ |
r |
Intent shared lock. |
intent_exclusive_ |
w |
Intent exclusive lock. |
shared_ |
R |
Shared lock. |
exclusive_ |
W |
Exclusive lock. |
Metrics per lock type and mode combination Copied
Dimensions: connection_name, process, server, lock_type
| Metric name pattern | Type | Unit | Description |
|---|---|---|---|
server_locks_{mode}acquireCount |
counter | Number of times the lock was acquired in this mode. | |
server_locks_{mode}acquireWaitCount |
counter | Number of times lock acquisition had to wait. | |
server_locks_{mode}timeAcquiringMicros |
counter | microseconds | Cumulative time spent waiting to acquire the lock. |
server_locks_{mode}deadlockCount |
counter | Number of deadlocks encountered while acquiring the lock. |
Example metric names Copied
server_locks_intent_shared_acquireCountserver_locks_exclusive_timeAcquiringMicrosserver_locks_shared_deadlockCount
Database statistics metrics Copied
The following metrics are collected from the dbStats command and are published once per monitored database, per server host (standalone), or per replica set (replica set mode).
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
db_object_count |
counter | connection_name, process, server or replica_set, database_name |
Number of documents in the database. | |
db_data_size |
gauge | bytes | connection_name, process, server or replica_set, database_name |
Uncompressed size of all documents in the database. |
db_index_size |
gauge | bytes | connection_name, process, server or replica_set, database_name |
Total size of all indexes in the database. |
db_storage_size |
gauge | bytes | connection_name, process, server or replica_set, database_name |
Total storage space allocated to the database, including free space. |
db_collections |
counter | connection_name, process, server or replica_set, database_name |
Number of collections in the database. |
Note
Theserverdimension is used for standalone deployments, while thereplica_setdimension is used for replica set deployments.
Connection pool statistics metrics Copied
The following metrics are collected from the connPoolStats command and are published once per monitored server host.
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
connpool_numClientConnections |
gauge | connection_name, process, server |
Number of active outgoing client connections from the server. | |
connpool_numAScopedConnections |
gauge | connection_name, process, server |
Number of active scoped connections. | |
connpool_totalInUse |
gauge | connection_name, process, server |
Total number of connections currently in use across all pools. | |
connpool_totalAvailable |
gauge | connection_name, process, server |
Total number of connections available across all pools. | |
connpool_totalLeased |
gauge | connection_name, process, server |
Total number of connections currently leased. | |
connpool_totalCreated |
counter | connection_name, process, server |
Cumulative number of connections created across all pools. | |
connpool_totalRefreshing |
gauge | connection_name, process, server |
Total number of connections being refreshed. | |
connpool_totalRefreshed |
counter | connection_name, process, server |
Cumulative number of connections that have been refreshed. | |
connpool_totalWasNeverUsed |
counter | connection_name, process, server |
Cumulative number of connections that were created but never used. |
User session metrics Copied
The following metrics are collected by aggregating the config.system.sessions collection and are published once per MongoDB user. These metrics are available in both standalone and replica set deployments.
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
session_count |
gauge | connection_name, process, server, user |
Number of active sessions for the user. | |
session_last_updated |
attribute | connection_name, process, server, user |
ISO 8601 timestamp of the most recent session activity for the user. |
The user dimension identifies the MongoDB username associated with the sessions.
Replica set metrics Copied
The following metrics are collected from the replSetGetStatus command and are published once per replica set member. These are only available when the plugin is configured with a replica set URI.
| Metric | Type | Unit | Dimensions | Description |
|---|---|---|---|---|
rs_member_state |
status | connection_name, process, replica_set, member_name |
Current state of the member as a string (for example, PRIMARY, SECONDARY, ARBITER). |
|
rs_member_stateCode |
gauge | connection_name, process, replica_set, member_name |
Numeric state code of the member (for example, 1 for PRIMARY, 2 for SECONDARY). |
|
rs_member_health |
status | connection_name, process, replica_set, member_name |
Health of the member: UP or DOWN. |
|
rs_member_optimeDate |
gauge | epoch milliseconds | connection_name, process, replica_set, member_name |
Timestamp of the last oplog entry applied by this member. Only published for healthy (UP) members when there is a reachable primary. |
rs_member_replicationLag |
gauge | seconds | connection_name, process, replica_set, member_name |
Replication lag relative to the primary, in seconds. Only published for healthy (UP) members when there is a reachable primary. |
rs_member_syncSourceHost |
attribute | connection_name, process, replica_set, member_name |
Hostname of the member this node is replicating from. Only published for non-primary members. |
Self-monitoring metrics Copied
The plugin publishes internal signal metrics to indicate the health of each collection cycle. These are published as two named signals per processor execution:
| Signal metric | Severity on failure | Description |
|---|---|---|
MongoDbConnection |
CRITICAL | Indicates whether the plugin successfully connected to MongoDB and executed the MongoDB command. |
DataPointProcessing |
CRITICAL | Indicates whether the command result was parsed and processed without errors. |
Self-monitoring metrics carry the following dimensions:
| Dimension | Description |
|---|---|
command_name |
The MongoDB command or operation that was executed (for example, serverStatus, dbStats, connPoolStats, replSetGetStatus, aggregate). |
connection_name |
The logical connection alias from configuration. |
server |
Server address, for standalone deployments. |
replica_set |
Replica set name, for replica set deployments. |
database_name |
Database name associated with the collection task. |
collector_name |
Name of the Collection Agent collector instance. |
Troubleshooting Copied
Kerberos authentication failure Copied
If Kerberos authentication fails, check the following:
- Verify that the connection URI includes
authMechanism=GSSAPIandauthSource=$external, and that the principal name is URL-encoded (@becomes%40). - When you use a keytab file, verify that
keytabPathpoints to a valid file that the Collection Agent can read, and that the principal in the keytab matches the principal in the URI. - Verify that a
krb5.conffile is available to the Collection Agent JVM. For the lookup order, see Kerberos configuration file lookup. - Verify that the KDC is accessible from the host that runs the Collection Agent, and that the system clocks are synchronized within the allowed Kerberos clock skew (typically 5 minutes).
Metrics are not appearing for a specific database Copied
If dbStats metrics are missing for a database, check the following:
- Verify that the database name is spelled correctly in
databaseNames. Ensure that the MongoDB user has permission to list all databases so that it can be discovered automatically. - The
MongoDbConnectionself-monitoring signal will be set toCRITICALif the plugin cannot connect or run the command. Review the Collection Agent logs for the specific error message.
Metrics stopped updating Copied
If metrics stop updating, check the following:
- Collection tasks that do not complete within the configured
collectionIntervalare cancelled. If your MongoDB server responds slowly, consider increasing thecollectionInterval. - Check the
MongoDbConnectionandDataPointProcessingself-monitoring signals forCRITICALalerts.
Missing replica set metrics Copied
If replica set metrics are not being displayed, check the following:
- Confirm that the connection URI includes the
replicaSetoption (for example,?replicaSet=myReplicaSet). Without it, the plugin runs in standalone mode and does not collectreplSetGetStatusmetrics. - Ensure that the MongoDB user has the
clusterMonitorrole, which is required to runreplSetGetStatusacross all replica set members.
rs_member_optimeDate and rs_member_replicationLag are not published Copied
These metrics are reported only for members that are currently UP and when a primary is reachable. If all members are in a non-primary state or the primary’s optime is unavailable, these metrics are suppressed.
TLS connection errors Copied
If you are experiencing TLS connection errors, check the following:
- Ensure that the
clientKeyfile is in PKCS#8 format. See Convert a client key file to PKCS#8 format for conversion instructions. - If you are using a custom CA, verify that the path in
caFileis correct and readable by the Collection Agent process. - If
clientCertis provided,clientKeymust also be provided, and vice versa.
Convert a client key file to PKCS#8 format Copied
The openssl genrsa command produces keys in PKCS#1 format by default. The MongoDB plugin requires the client key to be in PKCS#8 format.
To convert to PKCS#8 format, run the following:
openssl pkcs8 -topk8 -inform PEM -outform PEM -in client.key -out clientKey.pem -nocrypt
Use the resulting clientKey.pem as the value for the clientKey configuration field.