MongoDB2.6版本web
MongoDB3.0版本sql
相似於MySQL的slow logmongodb
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 --restdom
> 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的比例高就要考慮索引是否正確創建。rest
> 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掉:server
db.killOp("shard3:466404288")