如何在生产环境中跟踪Mongo DB查询响应时间?

Paw*_*wan 1 mongodb

我们是目前正在生产的应用程序中的一个Mongdb.

有时我们在用户前端遇到缓慢(即数据缓慢加载到已登录的用户)

我们想排除可能存在的缓慢问题.我的问题是,有什么方法可以知道Mongo数据库查询需要多长时间才能响应?

非常感谢你 .

更新的部分

谢谢,这是一个取自Mongo db开发框的样本结果

{ "ts" : ISODate("2013-01-02T19:11:16.822Z"), "op" : "query", "ns" : "ravi.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 1, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(65), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(4), "w" : NumberLong(5) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }

{ "ts" : ISODate("2013-01-02T19:10:16.822Z"), "op" : "query", "ns" : "ravi.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 1, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(66), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(4), "w" : NumberLong(4) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }
Run Code Online (Sandbox Code Playgroud)

但是从这一点我怎么才能真正知道每个查询花了多少时间?

小智 8

使用profiler,设置db.setProfilingLevel(2)为启用它.并db.system.profile.find().sort({$natural:-1})查看记录