Getting cluster info on mongo operations (Ruby)

Is there a way to get which cluster serviced a mongo operation from MongoId or the mongo driver? I’m trying to update some instrumentation (NewRelic) that collects Mongo response times to have a per-cluster breakdown (currently it just gets an aggregate time for all Mongo operations). I’m looking for something along the lines of mongo returning some metadata along with the response that associates it with the cluster that serviced the operation.

I’ve also already asked the NewRelic folks on this, currently waiting for a response. Asking here as well in case someone has any ideas.

Hi @Neil_Ongkingco,

It might help if you could elaborate a bit on what you’re hoping to accomplish. When you issue a find or aggregate command via the driver it will just return a cursor, which doesn’t include any information as to where the operation was executed.

I was looking to log metrics that track mongo operation response times per cluster. I’ve sorta figured something out using Mongo::Monitoring::Global.subscribe to subscribe to mongo driver commands and using event.address + event.database_name to figure out the cluster used by the operation. Psuedo code is something like this:

Mongo::Monitoring::Global.subscrbe( Mongo::Monitoring::COMMAND,

class MySubscriber
   def started(event)
      cluster_id = get_cluster_id_from(event.address, event.database_name)  #derive cluster from address and dbname
      #log metric using cluster id, event.command

Still working on get_cluster_id, but I think its doable using Mongoid::Config.clients along with event.address/database_name