mongoDB

MongoDB Monitoring

MongoDB ships with some great tools that lets you see what’s happening on many levels on your database.

I am not going to go into the specifics on the log file here, other than that this would be a must have when running mongoDB. If you don’t know how to set up mongo and specify the location of you log file, you can have a look at this post.

Use whatever tool you like to search/filter the content of you log file to get the information you look for. Another small note for log file is that when you are in the shell of mongoDB running a remotely server, you can type “show log global” to get the log for the remote server.

Mongostat

MongoDB ships with a statistic tool for your convenient so that you can monitor performance of your production server with mongoDB. I am not going to go deep into this on this post but rather give you the pointers on where to start using it.

To start monitoring your database on a high level you will have to start the mongostat. Similar to how you start mongdb shell you can type the following in a cmd window: “c:\mongodb-3.2.8\bin\mongostat.exe –host localhost –port=27018”. Mongostat will now display information every second for as long as you keep it running.

dbm1

Most of this is more or less self-explaining, and good documented here, and to get something valid out of this you will have to have a server running mongoDB with some action going on.

Mongotop

This is a great tool to analyze where mongoDB spends most of its efforts. To start monitoring this you have to open a new cmd and type: “c:\mongodb-3.2.8\bin\mongotop.exe –host localhost –port=27018”

dbm2

Again this is just a small step into a high level monitoring that can help you get some perspective on where to start digging deeper into logs to find performance issues.

If you want to get more information on your db and its health you should dig into db.stats() and db.serverStatus() also.

 

Profiling

MongoDB can capture slow queries for you so you can boost performance on the results you get. You have to do some small tweaks to get this up and running. To get started go to a mongo shell and type “show profile”

dbm3

As you can see from the results you have to set the profiling level = 2,  to log all queries.( setting the profiling level = 1 will only log slow queries)

First of all, lets add some data to a database:

dbm4

Secondly you have to set the profiling level higher the 0:

dbm5

To prove a point here I need to add a lot more data:

dbm6

If I now do a query on this data and then show the profiling I will get then following:

dbm7

So from here I can see that the query took 5ms. I can see that the docsExamined = 10020, and I can see that the stage = COLLSCAN. So it is actually scanning all the documents on the title column and returning it. So from this query profile I can see that I need an index on the column title.

To query you profile you can simply do this by typing: db.system.profile.findOne({op:’query’, ns:’demo.posts’}), here ns: = databasename.collectionname

In this case it will return the things we already know, but you get the point of why this is a super helpful tool analyzing your applications performance.

dbm8

 

Thanks for reading.

 

 

 

 

One thought on “MongoDB Monitoring

Comments are closed.