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:

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

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:

  1. Set up your Collection Agent plugin.

  2. Configure your mappings.

  3. 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 to use the system default credential cache (KRB5CCNAME / OS default).
      kerberos:
        # Path to a keytab file for the principal. (optional, mutually exclusive with ccachePath)
        # When set, the plugin performs a programmatic JAAS login using the keytab so that
        # authentication works without a prior kinit. The principal is read from the URI.
        keytabPath: /path/to/mongouser.keytab

        # Path to a Kerberos credential cache file. (optional, mutually exclusive with keytabPath)
        # When set, the plugin reads the TGT from this specific cache file.
        # When omitted, the cache is resolved via KRB5CCNAME or the OS default location.
        ccachePath: /path/to/krb5cc_file

    # 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 needed when you want to supply Kerberos credentials explicitly (for example, from a keytab or credential cache file).

If the Collection Agent JVM already has a valid Kerberos ticket cache obtained through kinit, omit the kerberos block.

Authentication modes Copied

No external Java Authentication and Authorization Service (JAAS) configuration file is required for any authentication mode. The plugin always performs a programmatic JAAS login by using Krb5LoginModule and attaches the resulting Subject to the MongoDB credential. Authentication is self-contained regardless of JAAS defaults on the JVM.

Mode How to configure Credential source
Keytab Set kerberos.keytabPath in the configuration Plugin logs in with the keytab without a prior kinit.
Credential cache (explicit path) Set kerberos.ccachePath in the configuration Plugin reads the ticket-granting ticket (TGT) from the specified cache file.
Credential cache (system default) Omit the kerberos block, or omit keytabPath and ccachePath Plugin resolves the cache through the KRB5CCNAME environment variable or the OS default location.

Credential cache location resolution order Copied

When ccachePath is not configured, Krb5LoginModule resolves the credential cache in the following order:

  1. KRB5CCNAME environment variable (for example, KRB5CCNAME=/tmp/krb5cc_1000).
  2. OS default location (for example, /tmp/krb5cc_<uid> on Linux or the API cache on macOS).

Kerberos configuration file lookup Copied

The JDK Kerberos stack locates krb5.conf file in the following order:

  1. -Djava.security.krb5.conf=<path> set on the Collection Agent JVM (recommended for non-default locations)
  2. JDK fallback: <java.home>/conf/security/krb5.conf
  3. OS default location:

Note

The Kerberos configuration file is JVM-global. All GSSAPI-authenticated MongoDB collectors running under the same Netprobe must share the same krb5.conf configuration.

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

Configure your mappings Copied

You can configure your dynamic mappings using a built-in or custom mapping in Dynamic Entities > Mapping.

  1. To use a built-in mapping, set Option to Built in, then select MongoDB V4 in the Built in > Name field.
  2. 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:

Database discovery Copied

When databaseNames is not configured, the plugin discovers which databases to monitor using the following fallback chain:

  1. It lists all available databases on the connected MongoDB instance.
  2. If the database list is not yet available at startup, it uses the default authentication database specified in the connection URI.
  3. If no default authentication database is specified in the URI, it uses the authSource of the connection credentials.
  4. 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
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

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

The server dimension is used for standalone deployments, while the replica_set dimension 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:

Metrics are not appearing for a specific database Copied

If dbStats metrics are missing for a database, check the following:

Metrics stopped updating Copied

If metrics stop updating, check the following:

Missing replica set metrics Copied

If replica set metrics are not being displayed, check the following:

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:

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.

["Geneos"] ["Geneos > Netprobe"] ["User Guide"]

Was this topic helpful?