Atatus Database Monitoring provides deep visibility into your MongoDB databases by collecting key performance metrics, slow operations, query samples, explain plans, and replication health.

To enable MongoDB monitoring, the Atatus Infra Agent must be installed and configured to connect directly to your MongoDB instance. This guide walks you through the required prerequisites and setup process for self-hosted MongoDB environments.

Before You Begin

Component Supported Versions
MongoDB 4.4, 5.0, 6.0, 7.0, 8.0
MongoDB Editions Community, Enterprise
Atatus Infra Agent 4.1.0 or higher

To enable MongoDB Database Monitoring with Atatus, complete the following steps:

Grant the Agent access to your MongoDB instances

Connect to the MongoDB shell, authenticate to the standalone instance, and create a read-only Atatus user in the admin database with required permissions.

1. Connect to your MongoDB shell and switch to the admin database:

copy
icon/buttons/copy

use admin
db.auth("admin", "<YOUR_ADMIN_PASSWORD>")

2. Create a read-only user for Atatus:

copy
icon/buttons/copy

db.createUser({
  "user": "atatus",
  "pwd": "<STRONG_PASSWORD>",
  "roles": [
    { role: "read", db: "admin" },
    { role: "read", db: "local" },
    { role: "clusterMonitor", db: "admin" }
  ]
})

Grant additional database monitoring permissions to the Atatus Agent user (Optional)

copy
icon/buttons/copy

db.grantRolesToUser("atatus", [
  { role: "read", db: "<DB_NAME>" },
  { role: "read", db: "<DB_NAME>" }
])

For monitoring all databases, grant the readAnyDatabase role (Optional)

copy
icon/buttons/copy

db.grantRolesToUser("atatus", [
  { role: "readAnyDatabase", db: "admin" }
])

Connect to the primary node, authenticate, and create a read-only Atatus user in the admin database with required permissions.

1. Connect to your MongoDB shell and switch to the admin database:

copy
icon/buttons/copy

use admin
db.auth("admin", "<YOUR_ADMIN_PASSWORD>")

2. Create a read-only user for Atatus:

copy
icon/buttons/copy

 db.createUser({
  "user": "atatus",
  "pwd": "<STRONG_PASSWORD>",
  "roles": [
    { role: "read", db: "admin" },
    { role: "read", db: "local" },
    { role: "clusterMonitor", db: "admin" }
  ]
})

Grant additional database monitoring permissions to the Atatus Agent user (Optional)

copy
icon/buttons/copy

db.grantRolesToUser("atatus", [
  { role: "read", db: "<DB_NAME>" },
  { role: "read", db: "<DB_NAME>" }
])

For monitoring all databases, grant the readAnyDatabase role (Optional)

copy
icon/buttons/copy

db.grantRolesToUser("atatus", [
  { role: "readAnyDatabase", db: "admin" }
])

Connect to the primary node of each shard, authenticate, and create a read-only Atatus user in the admin database with required permissions.

1. Connect to your MongoDB shell and switch to the admin database:

copy
icon/buttons/copy

use admin
db.auth("admin", "<YOUR_ADMIN_PASSWORD>")

2. Create a read-only user for Atatus:

copy
icon/buttons/copy

db.createUser({
  "user": "atatus",
  "pwd": "<STRONG_PASSWORD>",
  "roles": [
    { role: "read", db: "admin" },
    { role: "read", db: "local" },
    { role: "clusterMonitor", db: "admin" }
  ]
})

Grant additional database monitoring permissions to the Atatus Agent user (Optional)

copy
icon/buttons/copy

db.grantRolesToUser("atatus", [
  { role: "read", db: "<DB_NAME>" },
  { role: "read", db: "<DB_NAME>" }
])

For monitoring all databases, grant the readAnyDatabase role (Optional)

copy
icon/buttons/copy

db.grantRolesToUser("atatus", [
  { role: "readAnyDatabase", db: "admin" }
])

Configure Atatus Infra Agent

To enable Atatus monitoring for a standalone MongoDB instance, update the configuration file by adding the following configuration to /etc/atatus-infra-agent/conf.d/mongodb.d/mongodb.yml:

copy
icon/buttons/copy

metrics:
  - hosts: ["localhost:27017"]
    username: atatus
    password: <REPLACE_PASSWORD>
    connection_scheme: "mongodb"
    db_name: "admin"
    options: 
      connectTimeoutMS: 3000
      serverSelectionTimeoutMS: 2000
    dbm: true 
    cluster_name: <CLUSTER_NAME>

Note: Replace <STRONG_PASSWORD> with the password you created for the Atatus user.

To monitor a MongoDB replica set, the Agent must connect to all replica set members, including the arbiter.
Update the configuration file by adding the following configuration to /etc/atatus-infra-agent/conf.d/mongodb.d/mongodb.yml.

copy
icon/buttons/copy

metrics:
  - hosts:
      - <HOST_REPLICA_1>:<PORT>   # Primary node
    username: atatus
    password: <REPLACE_PASSWORD>
    connection_scheme: "mongodb"
    db_name: "admin"
    options:
      connectTimeoutMS: 3000
      serverSelectionTimeoutMS: 2000
    dbm: true
    cluster_name: <CLUSTER_NAME>
- hosts: - <HOST_REPLICA_2>:<PORT> # Secondary node username: atatus password: <REPLACE_PASSWORD> connection_scheme: "mongodb" db_name: "admin" options: connectTimeoutMS: 3000 serverSelectionTimeoutMS: 2000 dbm: true cluster_name: <CLUSTER_NAME>

Note: Replace <REPLICA_SET_NAME> with your replica set name and <STRONG_PASSWORD> with the password you created for the Atatus user.

To monitor a MongoDB sharded cluster, the Agent must connect to the mongos router(s) and all shard members.If multiple mongos routers are available, configure the Agent to connect to them for load balancing.
Update the configuration file by adding the following configuration to /etc/atatus-infra-agent/conf.d/mongodb.d/mongodb.yml:

copy
icon/buttons/copy

metrics:
  ## Mongos router
  - hosts: 
      - <HOST_MONGOS>:<PORT>
    username: atatus
    password: <REPLACE_PASSWORD>
    connection_scheme: "mongodb"
    db_name: "admin"
    options: 
      connectTimeoutMS: 3000
      serverSelectionTimeoutMS: 2000
    dbm: true
    cluster_name: <CLUSTER_NAME>
## Shard 1 - hosts: - <HOST_SHARD1_1>:<PORT> # Primary node username: atatus password: <REPLACE_PASSWORD> connection_scheme: "mongodb" db_name: "admin" options: connectTimeoutMS: 3000 serverSelectionTimeoutMS: 2000 dbm: true cluster_name: <CLUSTER_NAME>
- hosts: - <HOST_SHARD1_2>:<PORT> # Secondary node username: atatus password: <REPLACE_PASSWORD> connection_scheme: "mongodb" db_name: "admin" options: connectTimeoutMS: 3000 serverSelectionTimeoutMS: 2000 dbm: true cluster_name: <CLUSTER_NAME>
## Shard 2 - hosts: - <HOST_SHARD2_1>:<PORT> # Primary node username: atatus password: <REPLACE_PASSWORD> connection_scheme: "mongodb" db_name: "admin" options: connectTimeoutMS: 3000 serverSelectionTimeoutMS: 2000 dbm: true cluster_name: <CLUSTER_NAME>
- hosts: - <HOST_SHARD2_2>:<PORT> # Secondary node username: atatus password: <REPLACE_PASSWORD> connection_scheme: "mongodb" db_name: "admin" options: connectTimeoutMS: 3000 serverSelectionTimeoutMS: 2000 dbm: true cluster_name: <CLUSTER_NAME>
## Config server - hosts: - <HOST_CONFIG_1>:<PORT> # Primary node username: atatus password: <REPLACE_PASSWORD> connection_scheme: "mongodb" db_name: "config" # Specific database for config servers options: connectTimeoutMS: 3000 serverSelectionTimeoutMS: 2000 dbm: true cluster_name: <CLUSTER_NAME>
- hosts: - <HOST_CONFIG_2>:<PORT> # Secondary node username: atatus password: <REPLACE_PASSWORD> connection_scheme: "mongodb" db_name: "config" # Specific database for config servers options: connectTimeoutMS: 3000 serverSelectionTimeoutMS: 2000 dbm: true cluster_name: <CLUSTER_NAME>

Note: Replace the mongos hosts with your actual mongos instances and <STRONG_PASSWORD> with the password you created for the Atatus user.

Restart the Atatus Infra Agent to apply the changes:

copy
icon/buttons/copy

sudo service atatus-infra-agent restart

Restart the Atatus Infra Agent to apply the changes:

copy
icon/buttons/copy

sudo service atatus-infra-agent restart

Restart the Atatus Infra Agent to apply the changes:

copy
icon/buttons/copy

sudo service atatus-infra-agent restart