Real-Time Diagnostics for MongoDB Using Built-In CLI Tools

After a MongoDB instance is up and running, keeping an eye on its health and performance is essential. MongoDB ships with two lightweight command-line utilities—mongostat and mongotop—that give you immediate insight into server and collection-level activity without installing external agents.

mongostat – Server-wide Snapshot

mongostat samples global server metrics at a configurable interval and prints them in a tabular format. Its the quickest way to answer questions such as "Is the server saturated?" or "Are we creating too many connections?"

$ mongostat --username root --authenticationDatabase admin --port 27017

Typical columns include:

  • insert/query/update/delete/getmore/command – per-second operation counters
  • flushes – how many times data was flushed to disk in the last interval
  • vsize/res – virtual and resident memory footprint
  • conn – current number of open connections
  • qr|qw – queued readers and writers, a sign of lock contention

If you notice qr or qw climbing while throughput drops, the server is likely under heavy lock pressure.

mongotop – Colection-Level Heat Map

mongotop focuses on where the database is spending its time. It reports, per collection, the amount of time the server spent servicing reads and writes during the last sampling window.

$ mongotop 5

The optional numeric argument (5 in the example) sets the sampling period in seconds; the default is 1 s. Output resembles:

                    ns    total    read    write
  myApp.users       45ms    5ms     40ms
  myApp.orders      12ms   12ms      0ms
  myApp.logs         3ms    0ms      3ms

Key fields:

$ mongotop --locks 5

This view is helpful when troubleshooting multi-tenant clusters where individual databases contend for the global lock.

Tags: mongodb mongostat mongotop performance-monitoring cli-tools

Posted on Fri, 24 Jul 2026 16:19:14 +0000 by day_tripperz