6 Useful Tools to Monitor MongoDB Performance

We recently showed how to install MongoDB in Ubuntu 18.04. Once you have successfully deployed your database, you need to monitor its performance while it is running. This is one of the most important tasks under database administration.

Luckily enough, MongoDB provides various methods for retrieving its performance and activity. In this article, we will look at monitoring utilities and database commands for reporting statistics about the state of a running MongoDB instance.

1. Mongostat

Mongostat is similar in functionality to vmstat monitoring tool, which is available on all major Unix-like operating systems such as Linux, FreeBSD, Solaris as well as MacOS. Mongostat is used to get a quick overview of the status of your database; it provides a dynamic real-time view of a running mongod or mongos instance. It retrieves the counts of database operations by type, such as insert, query, update, delete and more.

You can run mongostat as shown. Note that if you have authentication enabled, put the user password in single quotes to avoid getting an error, especially if you have special characters in it.

$ mongostat -u "root" -p '[email protected]!#@%$admin1' --authenticationDatabase "admin"
Monitor MongoDB Performance
Monitor MongoDB Performance

For more mongostat usage options, type the following command.

$ mongostat --help 

2. Mongotop

Mongotop also provides a dynamic real-time view of a running MongoDB instance. It tracks the amount of time a MongoDB instance spends reading and writing data. It returns values every second, by default.

$ mongotop -u "root" -p '[email protected]!#@%$admin1'  --authenticationDatabase "admin"
Monitor MongoDB Activity
Monitor MongoDB Activity

For more mongotop usage options, type the following command.

$ mongotop --help 

3. serverStatus Command

First, you need to run the following command to login into mongo shell.

$ mongo -u "root" -p '[email protected]!#@%$admin1' --authenticationDatabase "admin"

Then run the serverStatus command, which provides an overview of the database’s state, by collecting statistics about the instance.

>db.runCommand( { serverStatus: 1 } )

4. dbStats Command

The dbStats command returns storage statistics for a particular database, such as the amount of storage used, the quantity of data contained in the database, and object, collection, and index counters.

>db.runCommand({ dbStats: 1 } )

5. collStats

collStats command is used to collect statistics similar to that provided by dbStats on the collection level, but its output includes a count of the objects in the collection, the size of the collection, the amount of disk space consumed by the collection, and information concerning its indexes.

>db.runCommand( { collStats : "aurthors", scale: 1024 } )

6. replSetGetStatus Command

The replSetGetStatus command outputs the status of the replica set from the perspective of the server that processed the command. This command must be run against the admin database in the followiing form.

>db.adminCommand( { replSetGetStatus : 1 } )

In this addition to the above utilities and database commands, you can also use supported third party monitoring tools either directly, or via their own plugins. These include mtop, munin and nagios.

For more information, consult: Monitoring for MongoDB Documentation.

That’s it for now! In this article, we have covered some useful monitoring utilities and database commands for reporting statistics about the state of a running MongoDB instance. Use the feedback form below to ask any questions or share your thoughts with us.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

1 thought on “6 Useful Tools to Monitor MongoDB Performance”

  1. Hi, I run the command “db.stats( )“, here I got the following details:

    "db" : "test",
    "collections" : 4,
    "objects" : 7,
    "avgObjSize" : 66.28571428571429,
    "dataSize" : 464,
    "storageSize" : 32768

    Which is the Unit of dataSize, avgObjSize and storageSize ?


Leave a Reply to PRASHITH Cancel reply

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.