MongoDB Connections and WiredTiger Cache Status
Summarizes connection usage and cache fill via serverStatus. Tells you whether the working set fits in RAM.
const s = db.serverStatus();
const wt = s.wiredTiger.cache;
({
connections_current: s.connections.current,
connections_available: s.connections.available,
cache_max_gb: +(wt["maximum bytes configured"] / 1073741824).toFixed(2),
cache_used_gb: +(wt["bytes currently in the cache"] / 1073741824).toFixed(2),
cache_dirty_gb: +(wt["tracked dirty bytes in the cache"] / 1073741824).toFixed(2),
pages_read_into_cache: wt["pages read into cache"],
uptime_hours: +(s.uptime / 3600).toFixed(1)
});WiredTiger cache dirty percentage above 20% triggers aggressive foreground application thread eviction.
- This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
- Prior to executing on production systems under high load, verify the target database version (Min. Version: 4.0).
- Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.
Engineering Triad: Related Runbooks & Incident Response
Which production incidents and emergency drills execute this script as a diagnosis step?
MongoDB Connection Exhaustion: Find the Client Filling the Pool
Identifies connections by client and application, distinguishes pool leaks from connection storms, and guides safe response when MongoDB approaches its connection limit.
MongoDB WiredTiger Cache Pressure: Working Set Does Not Fit in RAM
Reads cache fill, dirty ratio and eviction pressure; finds index and query issues that inflate the working set. Guides decisions on cache size, index cleanup and hardware.
Other MONGODB Diagnostic Scripts
View All (100)Find Long-Running Operations in MongoDB (currentOp)
Lists active operations running longer than 5 seconds with plan summary and lock-wait info. Helps pick the operation to kill during a slowdown.
MongoDB Collection and Index Sizes
Ranks collections by document count, data, storage and index size. Used for capacity planning and spotting bloated indexes.
Find Unused Indexes in MongoDB ($indexStats)
Lists never-used indexes per collection. Offers cleanup candidates to cut write cost and memory use.
MongoDB Replica Set Lag and Oplog Window
Shows member state, lag behind the primary and the oplog window. Monitors replication health and resync risk.