Mongo Database Diagnositcs CheatSheet

 Mongo Database Diagnositcs CheatSheet:


Mongo DB comes with three default db's, local,config,admin. And as application gets deployed there will be other app DB's created. When it comes to diagnostics, it will be good to have short CheatSheet of commands/steps.

First Look for errors/warnings/debug messages on  mongod.log

Current view current Log Level on Mongo DB can be found by


>db.getLogComponent();


> db.setLogLevel(1)     (this will set default verbosity for all components) you can increase upto 5, more logs when using 5.

To set verbosity level for a specific component individually, run below. level can be 1-5( 5 does more chattiness). valid components (

accessControl,command,control,ftdc,geo,index,network,query,replication,replication.election,replication.heartbeats,replication.initialSync,replication.rollback,

recovery,sharding,storage,storage.journal,transaction,write)


>db.setLogLevel(<level>, <component>)




To Log Queries that are taking longer than 20 milliseconds


>db.setProfilingLevel(1,20)

0- no profiling data collected

1- only slow queries are logged

2- all queries logged regardless of speed


>show profile   (list queries took long time)


To see current utilization of mongo database use (aggregate stats),

mongostat --host myserver --port 27017 --rowcount 10

mongotop -- where mongo is spending most of the time

eg.   mongotop --host myhost --port 27017


For DB level stats on shell you can run  (in MegaBytes)

>db.stats(1000000)

For collection level stats

> db.mycollection.stats()


To check the server stats

>db.serverStatus()

>>db.serverStatus().dur  (durability aspect)

>db.serverStatus().network  (network status whether saturating wires or not)

>db.serverStatus().mem  (momory stats)


GUI Tools:

Use: MMS (MongoDB Manager Service) aka Mongo Cloud Manager

Use: MongoDB Ops Manager

With Cloud manager, we can easily

  1. Monitor important stats like opcounters and connections at 1 minute granularity
  2. Receive alerts when key metrics are out of range
  3. Automate backups
  4. Upgrade MongoDB with zero downtime
  5. Easily create sharded clusters and replica sets

No comments: