Finding originating client from db.currentOp().inprog in sharded environment

427 views
Skip to first unread message

Simone Sciarrati

unread,
Jan 23, 2014, 4:19:59 AM1/23/14
to mongod...@googlegroups.com
Hi,

I am trying to find out which client is running an expensive query on
one cluster. On each mongod replica set primary we monitor for slow
and long running queries but the originating IP and port refers to the
mongos rather than the original client.

On the mongos I get the same:

db.currentOp().inprog.forEach(function(d){ if (d.ns == "a.b" &&
d.secs_running > 100) printjson(d.client_s)})

"10.9.41.16:50671"
"10.9.41.16:41383"
"10.9.41.16:60691"
"10.9.41.16:38513"
"10.9.41.16:57821"
"10.9.41.16:47799"

This is the mongos itself. I have searched the mongos logs for
references to the connection / port but I didn't find anything
useful, I am obviously looking in the wrong place and need advice.

Thanks,

S

Anil Kumar

unread,
Jan 27, 2014, 10:47:24 AM1/27/14
to mongod...@googlegroups.com
Simone,

Currently, I don't see a good / easy way of finding the client that caused an operation on the mongodb instance in sharded environment. 

Having said that, I believe it should still be achievable by looking at the clients connected to the shard that caused the operation on mongodb (based on the "opid") and working back-words to find the logical places where such operations occur.

I see your pain in doing such an exercise and believe such information being available readily via some command would make more sense.

Anil

William Zola

unread,
Jan 28, 2014, 12:50:23 PM1/28/14
to mongod...@googlegroups.com
Hi Simone!

It's possible to trace this down, but only if you make some changes to your application code.  If you add a $comment to the query, it will be visible in the db.currentOp() output.  If you change your application such that it puts in identifiable information in a $comment every time it runs the query ( I suggest using all of hostname, executable, port#, file, and function) , it should be straightforward to track down the source of the problematic query.


 -William 

Simone Sciarrati

unread,
Feb 4, 2014, 7:28:28 PM2/4/14
to mongod...@googlegroups.com
Hi,

Is there any intention of providing this traceability without having
to change application code? I think having this info directly in mongo
would be the most appropriate place, mongos knows where the connection
is coming from and what it is asking, this could be reported in
db.currentOp() as the connection id.

I see the point of adding a comment in the code, but having that info
in mongo seems the right place and helps in situation where for
example you might have to allow many people to run custom manual
queries or when you are investigating unauthorised access.

S
> --
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
>
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Anil Kumar

unread,
Feb 5, 2014, 10:32:52 AM2/5/14
to mongod...@googlegroups.com
Hi Simone,

I would suggest raising a Jira ticket (https://jira.mongodb.org/browse/SERVER) for this specific issue of making comment implicit in the connectivity from mongo shell. 

For slow queries logging in mongos, there is an open server Jira ticket https://jira.mongodb.org/browse/SERVER-2926 that may be helpful as well in sharded environment and I would suggest you vote-up the same.

Anil
Reply all
Reply to author
Forward
0 new messages