标签:
MongoDB2.6版本
MongoDB3.0版本
类似于MySQL的slow log
Profiler默认是关闭的,你可以选择全部开启,或者有慢查询的时候开启。
db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all
> use test switched to db test > db.setProfilingLevel(2) 2015-07-01T00:24:49.770-0700 trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 2015-07-01T00:24:49.774-0700 reconnect 127.0.0.1:27017 (127.0.0.1) ok { "was" : 0, "slowms" : 100, "ok" : 1 } > db.getProfilingLevel() 2 > db.system.profile.find().sort({$natural:-1})
如果需要打开web控制台的话,需要在mongod启动的时候加上--httpinterface --rest
> db.stats() { "db" : "test", "collections" : 6, "objects" : 2309992, "avgObjSize" : 48.00180260364538, "dataSize" : 110883780, "storageSize" : 198164480, "numExtents" : 27, "indexes" : 3, "indexSize" : 74990272, "fileSize" : 469762048, "nsSizeMB" : 16, "dataFileVersion" : { "major" : 4, "minor" : 5 }, "extentFreeList" : { "num" : 0, "totalSize" : 0 }, "ok" : 1 }
> db.serverStatus() { "host" : "localhost.localdomain", "version" : "2.6.9", "process" : "mongod", "pid" : NumberLong(22871), "uptime" : 1558, "uptimeMillis" : NumberLong(1558300), "uptimeEstimate" : 1428, "localTime" : ISODate("2015-07-01T07:30:33.497Z"), "asserts" : { "regular" : 0, "warning" : 0, "msg" : 0, "user" : 1, "rollovers" : 0 }, "backgroundFlushing" : { "flushes" : 25, "total_ms" : 2, "average_ms" : 0.08, "last_ms" : 0, "last_finished" : ISODate("2015-07-01T07:29:35.233Z") }, ……… }
需要注意两个地方:
connections 当前连接和可用连接数,到2000个连接就属于比较多的(要根据你的机器性能和业务来设定),所以设大了没意义。设个合理值的话,到达这个值mongodb就拒绝新的连接请求,避免被太多的连接拖垮。
indexCounters:btree:misses 索引的不命中数,和hits的比例高就要考虑索引是否正确建立。
> db.currentOp()
{ "opid" : "shard3:466404288", "active" : false, "waitingForLock" : false, "op" : "query", "ns" : "sd.usersEmails", "query" : { }, "client_s" : "10.121.13.8:34473", "desc" : "conn" }
如果需要可以kill掉:
db.killOp("shard3:466404288")
标签:
原文地址:http://www.cnblogs.com/xiaoit/p/4613402.html