Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

MongoDB Monitoring

MongoDB Monitoring

After you have installed, deployed, and enabled the MongoDB service, you must understand how MongoDB is running and check its performance. This way, you can respond well under heavy traffic and ensure MongoDB operates normally.

MongoDB provides two commands, mongostat and mongotop, to monitor how MongoDB is running.


mongostat command

mongostat is a status-monitoring tool that comes with mongodb and is used at the command line. It obtains mongodb's current running status at fixed intervals and outputs it. If you find that the database has suddenly become slow or has other problems, your first course of action should be to use mongostat to check mongo's status.

Start your Mongod service, enter the bin directory under your MongoDB installation directory, and then type the mongostat command, as shown below:



D:\set up\mongodb\bin>mongostat

The output of the above command is as follows:

mongotop command

mongotop is also a built-in tool under mongodb. mongotop provides a way to track a MongoDB instance and see where a large amount of time is spent on reading and writing data. mongotop provides statistics at the level of each collection. By default, mongotop returns values every second.

Start your Mongod service, enter the bin directory under your MongoDB installation directory, and then type the mongotop command, as shown below:



D:\set up\mongodb\bin>mongotop

The output of the above command is as follows:

Example with parameters



 E:\mongodb-win32-x86_64-2.2.1\bin>mongotop 10

The 10 after it is the ** parameter, which is optional; it is the length of waiting time, in seconds, between mongotop calls. By default, mongotop returns data every second.



 E:\mongodb-win32-x86_64-2.2.1\bin>mongotop --locks

To report the use of locks for each database, use mongotop -locks, which produces the following output:

Description of the output result fields: