Server Density Blog

Interesting devops tech stuff

Pssst… Server Density v2 is coming soon!

MongoDB Monitoring: current operations

Written by David Mytton

There are a number of built in tools and commands which can be used to get important information from MongoDB but because it is relatively new, it can be difficult to know what you need to be doing from an operational perspective to ensure that everything runs smoothly.

This is the last in a series of 6 posts about MongoDB monitoring based on a talk I gave at the MongoSV 2010 conference. View the series index here.

MongoDB Monitoring dashboard + alerting

We provide a MongoDB monitoring service to keep an eye on the health and performance of your MongoDB database cluster automatically and with alerting. Find out more here.

Current operations

Normally MongoDB operations will be very quick but if you have a long running query or a backlog of operations queuing up, you can use the db.currentOp() command to list every operation currently in progress. This can be used to locate long running operations and find out what is currently going on with your server.

		{
			"opid" : "shard3:466404288",
			"active" : false,
			"waitingForLock" : false,
			"op" : "query",
			"ns" : "sd.usersEmails",
			"query" : {
				
			},
			"client_s" : "10.121.13.8:34473",
			"desc" : "conn"
		},

This is an example from one of our servers. It has a number of fields:

Killing MongoDB operations

The most useful aspect of db.currentOp() is the opid because you can use this to kill operations. You could use this if there was a long running query which was locking up the database – be careful only to kill client operations as killing internal database operations such as replication sync can cause problems.

To kill an operation, you simply pass the opid to the db.killOp() method. For the example above, this would be:

db.killOp("shard3:466404288")

Enjoy this post? You may also like MongoDB Benchmarks