MongoDB Monitoring
The commands and metrics that show whether a MongoDB deployment is healthy, and the profiler settings that find slow operations.
Metrics that matter
Replication lag
Source: rs.status() member optimeDate
Seconds each secondary is behind the primary. Alert against the staleness budget your reads depend on.
Oplog window
Source: db.getReplicationInfo()
How far back the oplog reaches. If it falls below your maintenance window, a restarted secondary needs a full resync.
wiredTiger.cache bytes / configured max
Source: serverStatus()
Cache pressure. Sustained eviction with a full cache means the working set exceeds memory.
globalLock.currentQueue
Source: serverStatus()
Operations queued waiting for locks. Non-zero for sustained periods means contention.
connections.current / available
Source: serverStatus()
Connection saturation. Each connection costs about a megabyte of stack plus driver state.
opcounters and opLatencies
Source: serverStatus()
Operation mix and latency by type. A rising read latency with a flat operation count usually means cache or index trouble.
db.serverStatus().wiredTiger.cache["bytes currently in the cache"];
db.serverStatus().connections;
db.serverStatus().opLatencies;
rs.printSecondaryReplicationInfo();Live operations
// What is running now, longer than a second.
db.currentOp({ "secs_running": { $gt: 1 }, "active": true });
// Kill a runaway operation by its opid.
db.killOp(12345);Profiler
// Level 1 records operations slower than slowms. Level 2 records everything — very expensive.
db.setProfilingLevel(1, { slowms: 100, sampleRate: 1.0 });
db.system.profile.find({ millis: { $gt: 100 } })
.sort({ ts: -1 }).limit(10)
.forEach(op => printjson({
ts: op.ts, ms: op.millis, ns: op.ns,
plan: op.planSummary, docsExamined: op.docsExamined, nreturned: op.nreturned
}));planSummary: "COLLSCAN" is the clearest signal of a missing index. A large gap between
docsExamined and nreturned means the index that exists is not selective enough.
The profiler writes to a capped collection in each database, so it self-limits — but it does add write overhead. Sample rather than record everything on a busy system.
Free tooling
mongostat --uri="mongodb://…" 5 # operations, queues, cache, network per interval
mongotop --uri="mongodb://…" 5 # read and write time per collectionmongotop is the fastest way to find which collection is consuming the server's time.
Alerts worth having
- No primary in the replica set.
- Replication lag beyond the read-staleness budget.
- Oplog window below the longest expected maintenance outage.
- Connection count approaching the limit.
- WiredTiger cache eviction pressure sustained.
- Any member not in
PRIMARYorSECONDARYstate. - Disk usage projection for the data volume.
- For sharded clusters: balancer errors, jumbo chunks, and chunk imbalance between shards.