Loading

MongoDB Integration

<div class="condensed-table">
| | |
| --- | --- |
| Version | 1.16.0 (View all) |
| Compatible Kibana version(s) | 8.13.0 or higher |
| Supported Serverless project types
What’s this? | Security
Observability |
| Subscription level
What’s this? | Basic |
| Level of support
What’s this? | Elastic |

</div>
This integration is used to fetch logs and metrics from MongoDB.

When configuring the hosts option, MongoDB URIs must adhere to the following formats:

  • Simple: mongodb://[user:pass@]host[:port][?options]
  • Complex: mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]

Examples of URIs can vary from simple to complex:

  • Simple: localhost
  • Complex: mongodb://myuser:mypass@localhost:40001", "otherhost:40001

Additional supported URI examples include:

  • Replica set: mongodb://localhost:27017,localhost:27022,localhost:27023/?replicaSet=dbrs
  • Direct connection: mongodb://localhost:27017/?directConnection=true

When using the directConnection=true parameter in the connection URI, all operations are executed on the specified host. It’s important to explicitly include directConnection=true in the URI as it won’t be automatically added.

  • Authentication: mongodb://username:password@host:port/authSource=$external?authMechanism=PLAIN

When specifying authMechanism as PLAIN, it indicates the use of the PLAIN authentication mechanism, which is commonly associated with LDAP.

authSource can be used to specify the name of the database that has the collection with the user credentials.

In MongoDB, authSource=$external is a special authentication database used for authenticating users externally, such as via LDAP.

The username and password can either be included in the URI or set using the respective configuration options. If included in the URI, these credentials take precedence over any configured username and password configuration options.

The log dataset is tested with logs from versions v3.2.11 and v4.4.4 in plaintext and json formats. The collstats, dbstats, metrics, replstatus and status datasets are tested with MongoDB 5.0 and are expected to work with all versions >= 5.0.

In order to use the metrics datasets, the MongoDB user specified in the package configuration needs to have certain privileges.

We recommend using the clusterMonitor role to cover all the necessary privileges.

You can use the following command in Mongo shell to create the privileged user (make sure you are using the admin db by using db command in Mongo shell).

db.createUser(
    {
        user: "beats",
        pwd: "pass",
        roles: ["clusterMonitor"]
    }
)

You can use the following command in Mongo shell to authenticate a user against a specific database with the provided username and password (make sure you are using the admin db by using db command in Mongo shell).

db.auth(user, pass)

You can use the following command in Mongo shell to grant the role to an existing user (make sure you are using the admin db by using db command in Mongo shell).

db.grantRolesToUser("user", ["clusterMonitor"])

The log dataset collects the MongoDB logs.

The fields reported are:

ECS Field Reference

Please refer to the following document for detailed information on ECS fields.

The collstats dataset uses the top administrative command to return usage statistics for each collection. It provides the amount of time, in microseconds, used and a count of operations for the following types: total, readLock, writeLock, queries, getmore, insert, update, remove, and commands.

It requires the following privileges, which is covered by the clusterMonitor role:

The fields reported are:

ECS Field Reference

Please refer to the following document for detailed information on ECS fields.

The dbstats dataset collects storage statistics for a given database.

It requires the following privileges, which is covered by the clusterMonitor role:

The fields reported are:

ECS Field Reference

Please refer to the following document for detailed information on ECS fields.

It requires the following privileges, which is covered by the clusterMonitor role:

The fields reported are:

ECS Field Reference

Please refer to the following document for detailed information on ECS fields.

The replstatus dataset collects status of the replica set. It requires the following privileges, which is covered by the clusterMonitor role:

The fields reported are:

ECS Field Reference

Please refer to the following document for detailed information on ECS fields.

The status returns a document that provides an overview of the database’s state.

It requires the following privileges, which is covered by the clusterMonitor role:

The fields reported are:

ECS Field Reference

Please refer to the following document for detailed information on ECS fields.