Monitoring and Diagnostics

Mongostat

mongostat is a great utility which exposes many internal MongoDB metrics. For any MongoDB related issues it is a good start for the analysis of performance issues.

Query Profiler

Use the Database Profiler to analyze slow queries.

db.currentOp() is another way to get a snapshot of what is currently happening.

Http Console

The mongod process includes a simple diagnostic screen at http://localhost:28017/. See the Http Interface docs for more information.

mongo Shell Diagnostic Commands

  • db.serverStatus()
  • db.stats()
    • Stats on the current database. Command takes some time to run, typically a few seconds unless the .ns file is very large (via use of --nssize). While running other operations may be blocked.
    • fileSize is the total size of all files allocated for the db.
  • db.foo.find().explain()
    • explain plan
  • help
    • db.help()
    • db.foo.help()

Trending/Monitoring Adaptors

Chris Lea from (mt) Media Temple has made an easy to install Ubuntu package for the munin plugin.

Hosted Monitoring

Database Record/Replay (diagLogging command)

Recording database operations, and replaying them later, is sometimes a good way to reproduce certain problems in a controlled environment.

To enable logging:

db._adminCommand( { diagLogging : 1 } )

To disable:

db._adminCommand( { diagLogging : 0 } )

Values for diagLogging:

  • 0 off. Also flushes any pending data to the file.
  • 1 log writes
  • 2 log reads
  • 3 log both
    Note: if you log reads, it will record the findOnes above and if you replay them, that will have an effect!

Output is written to diaglog.bin_ in the /data/db/ directory (unless --dbpath is specified).

To replay the logged events:

nc ''database_server_ip'' 27017 < ''somelog.bin'' | hexdump -c

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.

blog comments powered by Disqus