Monitoring Tooling / Command-Line Monitoring with mongotop and mongostat

Code Recap: Command-Line Monitoring with mongotop and mongostat

mongostat

The mongostat command provides real-time statistics about the operations performed by MongoDB instances in a cluster. It shows metrics such as insert, query, update, delete, and command rates. Additionally, it logs system resource usage like memory (vsize and res), connection="" counts="" (conn), network traffic (net_in and net_out), and replica set state (repl). This command is primarily used to monitor database activity and diagnose potential performance issues.

mongostat

host insert query update delete getmore command dirty  used flushes vsize  res qrw arw net_in net_out conn              set repl                time
security-shard-00-00.xwgj1.mongodb.net:27017     *0    *0     *0     *0       1    13|0  0.0% 77.0%       0 4.14G 659M 0|0 0|0  3.81k   97.6k   57 Security-shard-0  SEC Mar  6 09:24:43.662
security-shard-00-01.xwgj1.mongodb.net:27017     *0    *0     *0     *0       6    19|0  0.0% 79.4%       0 5.13G 694M 0|0 0|0  11.8k    114k   73 Security-shard-0  SLV Mar  6 09:24:43.934
security-shard-00-02.xwgj1.mongodb.net:27017     *0    *0     *0     *0       1    12|0  0.1% 77.6%       0 4.14G 654M 0|0 0|0  3.86k    110k   59 Security-shard-0  SEC Mar  6 09:24:43.233

mongotop

The mongotop command shows how much time MongoDB spends on read and write operations for each namespace (ns), which is a combination of database and collection names (e.g., config.image_collection). The total column displays the combined read and write time in milliseconds, while read and write show the breakdown of time spent on each type of operation during the sampling interval. This output helps administrators identify activity levels and potential performance bottlenecks for specific collections or commands.

mongotop
                     ns    total    read    write    

2025-04-25T16:26:15-07:00
config.image_collection      6ms     6ms      0ms
    config.transactions      2ms     2ms      0ms
   admin.$cmd.aggregate      0ms     0ms      0ms
         admin.atlascli      0ms     0ms      0ms
      admin.system.keys      0ms     0ms      0ms
     admin.system.roles      0ms     0ms      0ms
     admin.system.users      0ms     0ms      0ms
   admin.system.version      0ms     0ms      0ms
        bookstore.books      0ms     0ms      0ms