Skip to main content
APA
Sponsored by CAST AI — Kubernetes cost optimization Better Stack — Uptime monitoring and log management
⚠️

Alert thresholds depend on the nature of your applications. Some queries may have arbitrary tolerance thresholds. Building an efficient monitoring platform takes time. 😉

MongoDB Prometheus Alert Rules

17 Prometheus alerting rules for MongoDB. Exported via percona/mongodb_exporter, dcu/mongodb_exporter, stefanprodan/mgob. These rules cover critical and warning conditions — copy and paste the YAML into your Prometheus configuration.

wget https://raw.githubusercontent.com/samber/awesome-prometheus-alerts/refs/heads/master/dist/rules/mongodb/percona-mongodb-exporter.yml
critical

2.9.1.1. MongoDB Down

MongoDB instance is down

  # 1m delay allows a restart without triggering an alert.
- alert: MongoDBDown
  expr: mongodb_up == 0
  for: 1m
  labels:
    severity: critical
  annotations:
    summary: MongoDB Down (instance {{ $labels.instance }})
    description: "MongoDB instance is down\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.9.1.2. Mongodb replica member unhealthy

MongoDB replica member is not healthy

  # 1m delay allows a restart without triggering an alert.
- alert: MongodbReplicaMemberUnhealthy
  expr: mongodb_rs_members_health == 0
  for: 1m
  labels:
    severity: critical
  annotations:
    summary: Mongodb replica member unhealthy (instance {{ $labels.instance }})
    description: "MongoDB replica member is not healthy\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.9.1.3. MongoDB replication lag (Percona)

Mongodb replication lag is more than 10s

- alert: MongoDBReplicationLag(Percona)
  expr: (mongodb_rs_members_optimeDate{member_state="PRIMARY"} - on (set) group_right mongodb_rs_members_optimeDate{member_state="SECONDARY"}) / 1000 > 10
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: MongoDB replication lag (Percona) (instance {{ $labels.instance }})
    description: "Mongodb replication lag is more than 10s\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.9.1.4. MongoDB replication headroom

MongoDB replication headroom is <= 0

  # This query mixes old (mongodb_mongod_*) and new (mongodb_rs_*) metric names. It requires the Percona exporter to run with --compatible-mode to expose both.
- alert: MongoDBReplicationHeadroom
  expr: sum(avg(mongodb_mongod_replset_oplog_head_timestamp - mongodb_mongod_replset_oplog_tail_timestamp)) - sum(avg(mongodb_rs_members_optimeDate{member_state="PRIMARY"} - on (set) group_right mongodb_rs_members_optimeDate{member_state="SECONDARY"})) <= 0
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: MongoDB replication headroom (instance {{ $labels.instance }})
    description: "MongoDB replication headroom is <= 0\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.9.1.5. MongoDB number cursors open (Percona)

Too many cursors opened by MongoDB for clients (> 10k)

- alert: MongoDBNumberCursorsOpen(Percona)
  expr: mongodb_ss_metrics_cursor_open{csr_type="total"} > 10 * 1000
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: MongoDB number cursors open (Percona) (instance {{ $labels.instance }})
    description: "Too many cursors opened by MongoDB for clients (> 10k)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.9.1.6. MongoDB cursors timeouts (Percona)

Too many cursors are timing out ({{ $value }} in the last minute)

- alert: MongoDBCursorsTimeouts(Percona)
  expr: increase(mongodb_ss_metrics_cursor_timedOut[1m]) > 100
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: MongoDB cursors timeouts (Percona) (instance {{ $labels.instance }})
    description: "Too many cursors are timing out ({{ $value }} in the last minute)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.9.1.7. MongoDB too many connections (Percona)

Too many connections (> 80%)

- alert: MongoDBTooManyConnections(Percona)
  expr: mongodb_ss_connections{conn_type="current"} / (mongodb_ss_connections{conn_type="current"} + mongodb_ss_connections{conn_type="available"}) * 100 > 80 and (mongodb_ss_connections{conn_type="current"} + mongodb_ss_connections{conn_type="available"}) > 0
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: MongoDB too many connections (Percona) (instance {{ $labels.instance }})
    description: "Too many connections (> 80%)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

2.9.2. dcu/mongodb_exporter (9 rules)

wget https://raw.githubusercontent.com/samber/awesome-prometheus-alerts/refs/heads/master/dist/rules/mongodb/dcu-mongodb-exporter.yml
critical

2.9.2.1. MongoDB replication lag (DCU)

Mongodb replication lag is more than 10s

- alert: MongoDBReplicationLag(DCU)
  expr: avg(mongodb_replset_member_optime_date{state="PRIMARY"}) - avg(mongodb_replset_member_optime_date{state="SECONDARY"}) > 10
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: MongoDB replication lag (DCU) (instance {{ $labels.instance }})
    description: "Mongodb replication lag is more than 10s\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.9.2.2. MongoDB replication Status 3

MongoDB Replication set member either perform startup self-checks, or transition from completing a rollback or resync

- alert: MongoDBReplicationStatus3
  expr: mongodb_replset_member_state == 3
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: MongoDB replication Status 3 (instance {{ $labels.instance }})
    description: "MongoDB Replication set member either perform startup self-checks, or transition from completing a rollback or resync\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.9.2.3. MongoDB replication Status 6

MongoDB Replication set member as seen from another member of the set, is not yet known

- alert: MongoDBReplicationStatus6
  expr: mongodb_replset_member_state == 6
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: MongoDB replication Status 6 (instance {{ $labels.instance }})
    description: "MongoDB Replication set member as seen from another member of the set, is not yet known\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.9.2.4. MongoDB replication Status 8

MongoDB Replication set member as seen from another member of the set, is unreachable

- alert: MongoDBReplicationStatus8
  expr: mongodb_replset_member_state == 8
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: MongoDB replication Status 8 (instance {{ $labels.instance }})
    description: "MongoDB Replication set member as seen from another member of the set, is unreachable\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.9.2.5. MongoDB replication Status 9

MongoDB Replication set member is actively performing a rollback. Data is not available for reads

- alert: MongoDBReplicationStatus9
  expr: mongodb_replset_member_state == 9
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: MongoDB replication Status 9 (instance {{ $labels.instance }})
    description: "MongoDB Replication set member is actively performing a rollback. Data is not available for reads\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.9.2.6. MongoDB replication Status 10

MongoDB Replication set member was once in a replica set but was subsequently removed

- alert: MongoDBReplicationStatus10
  expr: mongodb_replset_member_state == 10
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: MongoDB replication Status 10 (instance {{ $labels.instance }})
    description: "MongoDB Replication set member was once in a replica set but was subsequently removed\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.9.2.7. MongoDB number cursors open (DCU)

Too many cursors opened by MongoDB for clients (> 10k)

- alert: MongoDBNumberCursorsOpen(DCU)
  expr: mongodb_metrics_cursor_open{state="total_open"} > 10000
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: MongoDB number cursors open (DCU) (instance {{ $labels.instance }})
    description: "Too many cursors opened by MongoDB for clients (> 10k)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.9.2.8. MongoDB cursors timeouts (DCU)

Too many cursors are timing out ({{ $value }} in the last minute)

- alert: MongoDBCursorsTimeouts(DCU)
  expr: increase(mongodb_metrics_cursor_timed_out_total[1m]) > 100
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: MongoDB cursors timeouts (DCU) (instance {{ $labels.instance }})
    description: "Too many cursors are timing out ({{ $value }} in the last minute)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.9.2.9. MongoDB too many connections (DCU)

Too many connections (> 80%)

- alert: MongoDBTooManyConnections(DCU)
  expr: mongodb_connections{state="current"} / (mongodb_connections{state="current"} + mongodb_connections{state="available"}) * 100 > 80 and (mongodb_connections{state="current"} + mongodb_connections{state="available"}) > 0
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: MongoDB too many connections (DCU) (instance {{ $labels.instance }})
    description: "Too many connections (> 80%)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

2.9.3. stefanprodan/mgob (1 rules)

wget https://raw.githubusercontent.com/samber/awesome-prometheus-alerts/refs/heads/master/dist/rules/mongodb/stefanprodan-mgob-exporter.yml
critical

2.9.3.1. Mgob backup failed

MongoDB backup has failed

- alert: MgobBackupFailed
  expr: changes(mgob_scheduler_backup_total{status="500"}[1h]) > 0
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: Mgob backup failed (instance {{ $labels.instance }})
    description: "MongoDB backup has failed\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"