MongoDB - Day 19 (MongoDB Monitoring)

Before reading this article, I highly recommend reading the following previous parts of the series:

Monitoring is a administer level work and a critical component of database administration. But I think we should have a basic knowledge of monitoring. Monitoring allow us to diagnose problems before they escalate to failures. Today I will give a brief introduction to monitoring and explain how we can monitor and maintain our database.

What is Monitoring

Monitoring helps us to understand how our production system will hold up before deploying and determine where we will need to add capacity. A firm grasp of MongoDB’s reporting allows us to assess the state of our database and maintain our deployment without crisis and failures.

How MongoDB perform monitoring

MongoDB provides the following three methods for monitoring and collecting information about the state of currently running MongoDB instance.

  • Utilities
  • Database Commands
  • Monitoring Tools

Each method monitor the system and provide an overview about system performance and MongoDB instance. Each method is suitable for some specific condition. In this article I will explain several monitoring methods and also explain which method should be used in what condition.


Utilities are most important and useful for diagnosing the issues and assess the state of current MongoDB instance and database. MongoDB provides number of utilities that return statistics about MongoDB instance and current activity.

MongoDB contains the following utilities.


mongostat  first checks the status of all running mongod instance and returns the counter of database operations. These counter contains information about insert, update, delete, queries and cursors. The mongostat  returns information about load distribution over server. The mongostat also shows when we are hitting a page fault.

Use mongostat  when we want to understand load distribution or distribution of operation types.




First open a command prompt and run one or more mongod instance using “mongod” command. Now open another command prompt and run “mongostat” utility.

When we run “mongostat”, the  output will look like the following:

Figure 1: mongostat

In above example we can see that the output contains information about insert, query, update and delete operation. Value 0 indicate that the operation is not performed and 1 indicate that the operation has been performed. In above example all values of insert, update, delete, query is 0 because till now we did not performed any operation.

Now we delete some data from a collection. After that again run the “mongostat”  and examine the output.

Figure 2: Delete

Output of “mongostat” .

Figure 3: Output

In above image we can see that delete field contains value 1. Value 1  indicate that some data has been deleted from the database.


The mongotop  tracks and generate reports of current read and write activity for current MongoDB instance. The mongotop  generate the report on the collection basis. The mongotop  track and report the read and write activity for all the collections.

We can use mongotop to check the database activity and match our expectation. It means we can check that database performing the read and write operation as frequently as we expect or not. We can also check that the read and write activity matching our application intention or not.




Figure 4: Write Operation

The mongotop command generate report each second. If we want to provide some delay then we can pass number of seconds as parameter. If we use 10 after mongotop command, then MongoDB will generate report in every 10 seconds.


Figure 5: Interval

HTTP Console

MongoDB provide a simple web interface that exposes the monitoring and diagnostics information in a simple web page. The web interface is accessible at http://localhost:<Port_Number>. Port_Number is 1000 more than the port number on which current mongod instance in running.


First run a mongod instance using “--rest” option. The rest option is used to enable the REST API. REST API enables http interface, even if HTTP interface option is disabled.

First open a command prompt and run the following command:

mongod  --rest.

Now open a browser and access HTTP console at ” http://localhost:28017/

When we access the HTTP console, it will look like the following.

Figure 6: Access


MongoDB supports a number of command that return information about the state of database. Commands provide finer level granularity compared to utilities. MongoDB provides the followingscommands for monitoring.


The serverStatus command provide a general information about the database, memory use, disk use, cursor, network, index access and connection. This command run directly and output of this command is an account of state of current MongoDB instance. Main advantage of serverStatus command is that it doesn’t effect MongoDB performance and executes quickly.




Figure 7: output2


The dbStats command is used to monitor the state and storage capacity of a specific database. The dbStats command return a document that contain information about storage used and data volume in a database . This document also provide information about collection, object and index counters. To retrieve information about a database use “db.stats()” command.




Figure 8: Database


The collStats command return information about a collection. The collStats command resemble the information provided by dbStats command at collection level and adds some extra information such as size of collection, include a count of object in collection, disk space used by collection and information about indexes of collection.




Figure 9: Output3

Monitoring Tools

MongoDB supports number of monitoring tools either directly or through their own plugins. MongoDB uses the following two types of monitoring tools.

Self Hosted Monitoring Tools

Self hosted monitoring tools are mostly open source. We should install these tools on our own servers. Some important and useful tools are the following.



Motop Real time tool and shows current operations ordered by durations every second.
Gangila Generate a python script that contain operations per second, memory usage, btree statistics, master-slave status and current connections.
Munin Retrieves server statistics.

Hosted Monitoring Tools

These monitoring tools are not installed on own server, instead of this yje monitoring tools are provided as a hosted service using a paid subscription. Some important and useful tools are the following:



MongoDB Cloud Manager This is a cloud based monitoring tool and provide monitoring , backup and automation functionality.
Application Performance Management This tools is provided by IBM that supports monitor of MongoDB and other application and middleware.
Scout This tools support several plugins likes MongoDB Slow Queries and MongoDB Monitoring.

Today we learned different types of methods and commands, through which we can monitor our MongoDB system and increase the performance of MongoDB.

This is the last article of MongoDB series. Now this series has been completed. This series covered all the basic topics of MongoDB with their brief introduction. From the next article, I will explain some advanced topics in MongoDB.

Thanks to all the readers for becoming a vital part of the series. Really, you all motivated me for this series each time. You provided me suggestion many time and help to increase the quality of content.

Similar Articles