- Data Backup and Restores
- Monitoring and Reporting
- Importing and Exporting Data
- Conclusion
Monitoring and Reporting
MongoDB has several utilities and commands for viewing reports on data usage, database tasks, and performance.
I will cover only a few here, and I recommend that you read the MongoDB documentation for a more in-depth list of all utilities and commands and their options.
One of the most important commands, mongostat, outputs several statistics on queries at specified intervals. For example, take the following command:
mongostat -n 20
This command outputs query statistics every 20 seconds. Some of the more common output stats that this command displays in the shell are the following:
- inserts: The number of objects inserted into the database per second. If followed by an asterisk (*), the datum refers to a replicated operation.
- query: The number of query operations per second.
- update: The number of update operations per second.
- delete: The number of delete operations per second.
- conn: The total number of open connections.
To get a general status overview of database, disk, memory, and connection use, try the db.serverStatus() command. Running it from the shell produces some interesting results, as shown on my machine (some results have been omitted for brevity):
{ "host" : "Jesse-PC", "version" : "2.6.5", "process" : "mongod", "pid" : NumberLong(15464), "uptime" : 1115, "uptimeMillis" : NumberLong(1114648), "uptimeEstimate" : 1111, "localTime" : ISODate("2014-11-20T00:43:22.086Z"), "connections" : { "current" : 1, "available" : 999999, "totalCreated" : NumberLong(9) }, "dur" : { "commits" : 30, "journaledMB" : 0, "writeToDataFilesMB" : 0, "compression" : 0, "commitsInWriteLock" : 0, "earlyCommits" : 0, "timeMs" : { "dt" : 3060, "prepLogBuffer" : 0, "writeToJournal" : 0, "writeToDataFiles" : 0, "remapPrivateView" : 0 } }, "network" : { "bytesIn" : 22467, "bytesOut" : 1204643, "numRequests" : 361 }, "mem" : { "bits" : 64, "resident" : 72, "virtual" : 624, "supported" : true, "mapped" : 240, "mappedWithJournal" : 480 } }
For detailed storage information, use the db.stats() command from the Mongo shell; you should get similar formatted results:
{ "db" : "test", "collections" : 3, "objects" : 7, "avgObjSize" : 66.28571428571429, "dataSize" : 464, "storageSize" : 24576, "numExtents" : 3, "indexes" : 1, "indexSize" : 8176, "fileSize" : 67108864, "nsSizeMB" : 16 }