MongoDB tutoria...login
MongoDB tutorial
author:php.cn  update time:2022-04-21 17:49:03

MongoDB monitoring


After you have installed, deployed and enabled the MongoDB service, you must understand the operation of MongoDB and view the performance of MongoDB. This can cope well with large traffic and ensure the normal operation of MongoDB.

MongoDB provides two commands, mongostat and mongotop, to monitor the operation of MongoDB.


mongostat command

mongostat is the status detection tool that comes with mongodb and is used from the command line. It will obtain the current running status of mongodb at fixed intervals and output it. If you find that the database suddenly slows down or has other problems, your first step is to consider using mongostat to check the status of mongo.

Start your Mongod service and enter the bin directory under the MongoDB directory you installed. Then enter 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, provided by mongotop A method for tracking a MongoDB instance to see where a large amount of time is spent reading and writing data. mongotop provides per-collection level statistics. By default, mongotop returns a value every second.

Start your Mongod service and enter the bin directory under the MongoDB directory you installed. Then enter the mongotop command, as shown below:

D:\set up\mongodb\bin>mongotop

The above command execution output is as follows:

Example with parameters

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

## The 10 following

# is the

<sleeptime> parameter, which can be omitted. The length of time to wait, in seconds, between mongotop waiting calls. By default mongotop returns data every second.

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

Reports the lock usage for each database, using mongotop-lock, which will produce the following output:

Output result field description:

  • #ns:

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

  • db:

    Contains the name of the database. The database named . is locked globally, not against a specific database.

  • total:

    The total amount of time mongod spent working on this namespace.

  • read:

    Provides that a large amount of time is spent by mongod performing read operations in this namespace.

  • write:

    Provide this namespace for write operations, which mongod spends a lot of time on.