Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

MongoDB monitoring


May 17, 2021 MongoDB


Table of contents


MongoDB monitoring

After you have installed the deployment and allowed the MongoDB service, you must understand how MongoDB is performing and review the performance of MongoDB. This is a good response to high traffic conditions and ensures that MongoDB is functioning properly.

Two commands, Mongostat and mongotop, are available in MongoDB to monitor the operation of MongoDB.


mongostat command

Mongostat is mongodb's own state detection tool, which is used on the command line. I t gets the current running state of mongodb at regular intervals and outputs it. I f you find that the database is suddenly slowing down or has other problems, your first-hand action is to consider using mongostat to see the status of mongo.

Start your Mongod service, go to the bin directory in the MongoDB directory you installed, and enter the mongostat command, as follows:

D:\set up\mongodb\bin>mongostat

The output of the above commands is as follows:

MongoDB monitoring

Mongotop command

Mongotop is also a built-in tool under mongodb, which provides a way to track an instance of MongoDB and see which large amounts of time are spent reading and writing data. m ongotop provides statistics on the level of each collection. B y default, mongotop returns the value every second.

Start your Mongod service, go to the bin directory in the MongoDB directory you installed, and enter the mongotop command, as follows:

D:\set up\mongodb\bin>mongotop

The output of the above command execution is as follows:

MongoDB monitoring

With parameter instance

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

MongoDB monitoring

The next 10 are the parameters of slt;sleeptime, which can be used without waiting for the length of time, in seconds, between the mongotop wait calls. R eturns every second of the data via the default mongotop.

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

Report the use of locks for each database, using mongotop - locks, which will produce the following output:

MongoDB monitoring

The output field description:

  • Ns:

    Contains the database namespace, which combines the database name with the collection.

  • Db:

    Contains the name of the database. N amed . databases for global locking, not specific databases.

  • total:

    Mongod spends the time working on this namespace to provide the total amount.

  • read:

    Provides a lot of time, which mongod spends performing read operations in this namespace.

  • write:

    Providing this namespace for writing takes a lot of time.