Diagnostic tools
One of the important tools of a database system is diagnostic tools. Fortunately, MongoDB has built-in diagnostic tools that enable developers to diagnose the server or get a brief report from the system.
We have the following utilities placed in this group:
mongostat
mongotop
mongosniff
mongoperf
In the next sections, you can read a brief description of each utility.
Learning about mongostat
This tool produces a brief summary of relevant statistics of the currently running MongoDB instances, either the mongod
or mongos
instance.
The following screenshot illustrates the output of this tool:
The preceding screenshot shows you the number of queries, update, insert, and delete operations from the database every second.
The following bullet list gives you a brief description for each column:
insert
: This refers to the number of insert operations per second.query
: This refers to the number of queries per second.update
: This refers to the number of update operations per second.delete
: This refers to the number of delete operations per second.getmore
: This refers to the number ofgetmore
operations (that is, theit
command in mongo shell) per second.command
: This refers to the number of executed commands since the lastmongostat
call.flushes
: This refers to the number offsync
operations at the time of the lastmongostat
execution. Thefsync
operation is a system call that flushes all dirty in-memory pages to the disk.mapped
: This refers to the total amount of data mapped in megabytes.vsize
: This refers to the amount of virtual memory in megabytes used by the process at the time of the lastmongostat
execution.res
: This refers to the amount of resident memory in megabytes used by the process at the time of the lastmongostat
execution.locked
: This refers to the percentage of time in a global write lock.idx miss
: This refers to the percentage of index access attempts that required a page fault.qr
: This refers to the number of clients in the queue that are waiting for read operations.qw
: This refers to the number of clients in the queue that are waiting for write operations.ar
: This refers to the number of clients that execute read operations.aw
: This refers to the number of clients that execute write operations.netIn
: This refers to the traffic received by the MongoDB instance in bytes.netOut
: This refers to the traffic sent by the MongoDB instance in bytes.conn
: This refers to the current total option connections.
The refresh interval can be changed using the following command:
mongostat [options] [sleep time]
Utilizing mongotop
The mongotop
utility provides you with a mechanism to get information about time spent on read/write operations. This command is similar to Unix's top
command.
The following screenshot shows you a simple usage of mongotop
:
Understanding mongosniff
The mongosniff
is a tool that is used to fetch live MongoDB collection statistics. While inserting or querying data from the MongoDB instances, you can run the mongosniff
command and connect it to your MongoDB instance to see what the database does.
Note
Please note that in order to use this utility, you should install the libpcap
library first. To install the
libpcap
library, please visit its official website at http://www.tcpdump.org/#documentation.
A simple usage of the mongosniff
tool is as follows:
sudo mongosniff --source NET lo0
The preceding command line will listen to the loopback interface (localhost). This interface is lo0
in Mac OS systems and lo
for other operating systems, usually. You can get the list for your network interfaces using the ifconfig
command. If you're using Windows as the operating system, you can get the list of network interfaces using the following command:
ipconfig /all
Utilizing mongoperf
The mongoperf
tool represents the disk I/O performance. It checks the I/O in a specified interval and illustrates it. This utility can be used independent of MongoDB.
File storage (GridFS) tools
With the help of GridFS, MongoDB can be used as a filesystem. The processes in this section are used to manage and control the GridFS feature.
There is one process in this category, which is as follows:
mongofiles
Understanding mongofiles
This utility enables developers to retrieve files that are stored in the database in the GridFS collection. The mongofiles
utility come in handy when developers need to interact with files stored in the database from the command-line environment.
The usage of this command looks like the following:
mongofiles <options> <commands> <filename>
The following example is a simple usage of this utility:
mongofiles -d mydb list
The preceding command line will retrieve all files in the GridFS collection from the mydb
database.
Note
For more information on mongofiles
, please visit the MongoDB documentation page at http://docs.mongodb.org/manual/reference/program/mongofiles/.