您好,登錄后才能下訂單哦!
Mongodb監控命令
一、監控工具
1、mongostat工具
默認為顯示每秒的統計信息
# mongostat -uroot -ppassword --authenticationDatabase admin -h292.168.x.xx --rowcount 10 1 connected to: 192.168.x.xx insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn set repl time *0 *0 *0 *0 0 3|0 0 1.19g 3.07g 85m 0 test:0.0% 0 0|0 0|0 178b 4k 6 rs0 SEC 21:02:36 *0 *0 *0 *0 0 3|0 0 1.19g 3.07g 85m 0 test:0.0% 0 0|0 0|0 342b 4k 6 rs0 SEC 21:02:37 *0 *0 *0 *0 0 1|0 0 1.19g 3.07g 85m 0 test:0.0% 0 0|0 0|0 62b 3k 6 rs0 SEC 21:02:38 *0 *0 *0 *0 0 3|0 1 1.19g 3.07g 85m 0 test:0.0% 0 0|0 0|0 342b 4k 6 rs0 SEC 21:02:39 *0 6 *0 *0 0 1|0 0 1.19g 3.07g 85m 0 test:0.0% 0 0|0 0|0 62b 3k 6 rs0 SEC 21:02:40 *0 *0 *0 *0 0 3|0 0 1.19g 3.07g 85m 0 test:0.0% 0 0|0 0|0 342b 4k 6 rs0 SEC 21:02:41 *0 *0 *0 *0 0 1|0 0 1.19g 3.07g 85m 0 test:0.0% 0 0|0 0|0 62b 3k 6 rs0 SEC 21:02:42 *0 *0 *0 *0 0 3|0 0 1.19g 3.07g 85m 0 test:0.0% 0 0|0 0|0 342b 4k 6 rs0 SEC 21:02:43 *0 *0 *0 *0 0 1|0 0 1.19g 3.07g 85m 0 test:0.0% 0 0|0 0|0 62b 3k 6 rs0 SEC 21:02:44 *0 *0 *0 *0 0 3|0 0 1.19g 3.07g 85m 0 db4:0.0% 0 0|0 0|0 342b 4k 6 rs0 SEC 21:02:45
可以添加 --discover顯示shard集群(連接mongos)和副本集的所有成員的統計信息。
輸出含義,參考:http://docs.mongodb.org/v2.6/reference/program/mongostat/
2、mongotop工具
顯示每個數據庫的集合的讀寫時間,或每個數據庫的讀寫鎖時間(--locks),默認為1秒。
# mongotop -uroot -ppassword --authenticationDatabase admin -h292.168.x.xx 5 connected to: 192.168.x.xx ns total read write 2015-06-10T13:23:51 db4.system.indexes 0ms 0ms 0ms db4.$cmd 0ms 0ms 0ms db2.system.namespaces 0ms 0ms 0ms db2.system.indexes 0ms 0ms 0ms db2.post 0ms 0ms 0ms db1.userX2 0ms 0ms 0ms db1.userX1 0ms 0ms 0ms ns total read write 2015-06-10T13:23:56 db4.system.indexes 0ms 0ms 0ms db4.$cmd 0ms 0ms 0ms db2.system.namespaces 0ms 0ms 0ms db2.system.indexes 0ms 0ms 0ms db2.post 0ms 0ms 0ms db1.userX2 0ms 0ms 0ms db1.userX1 0ms 0ms 0ms # mongotop -uroot -ppassword --authenticationDatabase admin -h292.168.x.xx 5 --locks connected to: 192.168.x.xx db total read write 2015-06-10T13:24:42 . 1ms 1ms 0ms test 0ms 0ms 0ms local 0ms 0ms 0ms db4 0ms 0ms 0ms db2 0ms 0ms 0ms db1 0ms 0ms 0ms admin 0ms 0ms 0ms db total read write 2015-06-10T13:24:47 test 0ms 0ms 0ms local 0ms 0ms 0ms db4 0ms 0ms 0ms db2 0ms 0ms 0ms db1 0ms 0ms 0ms admin 0ms 0ms 0ms . 0ms 0ms 0ms
輸出含義,參考:http://docs.mongodb.org/v2.6/reference/program/mongotop/
3、db.serverStatus()
參考:http://docs.mongodb.org/v2.6/reference/command/serverStatus/
4、db.stats()
> db.stats() { "db" : "db4", "collections" : 3, "objects" : 13, "avgObjSize" : 87.38461538461539, "dataSize" : 1136, "storageSize" : 24576, "numExtents" : 3, "indexes" : 3, "indexSize" : 24528, "fileSize" : 16777216, "nsSizeMB" : 16, "dataFileVersion" : { "major" : 4, "minor" : 5 }, "extentFreeList" : { "num" : 0, "totalSize" : 0 }, "ok" : 1 }
參考:http://docs.mongodb.org/v2.6/reference/command/dbStats/#dbcmd.dbStats
5、db.collect_name.stats()
{ "ns" : "db4.userInfo", "count" : 5, "size" : 560, "avgObjSize" : 112, "storageSize" : 8192, "numExtents" : 1, "nindexes" : 3, "lastExtentSize" : 8192, "paddingFactor" : 1, "systemFlags" : 1, "userFlags" : 1, "totalIndexSize" : 24528, "indexSizes" : { "_id_" : 8176, "name_hashed" : 8176, "age_1" : 8176 }, "ok" : 1 }
參考:http://docs.mongodb.org/v2.6/reference/command/collStats/#dbcmd.collStats
6、rs.status()
查詢副本集信息
> rs.status() { "set" : "rs0", "date" : ISODate("2015-06-11T04:02:55Z"), "myState" : 2, "syncingTo" : "192.168.x.xx:27018", "members" : [ { "_id" : 0, "name" : "192.168.x.xx:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 84674, "optime" : Timestamp(1435989328, 1), "optimeDate" : ISODate("2015-07-04T05:55:28Z"), "lastHeartbeat" : ISODate("2015-06-11T04:02:54Z"), "lastHeartbeatRecv" : ISODate("2015-06-11T04:02:54Z"), "pingMs" : 8, "syncingTo" : "192.168.x.xx:27018" }, { "_id" : 3, "name" : "192.168.x.xx:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 84676, "optime" : Timestamp(1435989328, 1), "optimeDate" : ISODate("2015-07-04T05:55:28Z"), "self" : true }, { "_id" : 4, "name" : "192.168.x.xx:27018", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 84674, "optime" : Timestamp(1435989328, 1), "optimeDate" : ISODate("2015-07-04T05:55:28Z"), "lastHeartbeat" : ISODate("2015-06-11T04:02:54Z"), "lastHeartbeatRecv" : ISODate("2015-06-11T04:02:55Z"), "pingMs" : 2, "electionTime" : Timestamp(1435803779, 1), "electionDate" : ISODate("2015-07-02T02:22:59Z") } ], "ok" : 1 }
參考:http://docs.mongodb.org/v2.6/reference/command/replSetGetStatus
二、診斷性能問題
1、Locks
分析 db.serverStatus() 輸出的 globalLock 部分:
"globalLock" : { "totalTime" : NumberLong("240481182000"), "lockTime" : NumberLong(11670085), "currentQueue" : { "total" : 0, "readers" : 0, "writers" : 0 }, "activeClients" : { "total" : 0, "readers" : 0, "writers" : 0 } }
If globalLock.currentQueue.total is consistently high, then there is a chance that a large number of requests are waiting for a lock.
This indicates a possible concurrency issue that may be affecting performance.
globalLock.totalTime : The value of totalTime represents the time, in microseconds, since the database last started and creation of the globalLock.
This is roughly equivalent to total server uptime.
lockTime/totalTime很大,表示鎖花費的時間長,導致性能下降。
2、內存
分析 db.serverStatus() 輸出的 mem 部分:
"mem" : { "bits" : 64, "resident" : 39, "virtual" : 2993, "supported" : true, "mapped" : 1119, "mappedWithJournal" : 2238 }
單位為M.
resident 表示mongodb進程占用的內存,如果是專用服務器,隨著mongodb使用內存的增加,這個參數的值會漸漸接近于系統內存。
如果這個參數的值,超過系統內存并且大量的數據存放在磁盤而不在內存中,我們需要增加硬件能力。
mapped 文件映射的內存量,這個值大致與mongodb數據庫的大小相同。
If this value is greater than the amount of system memory, some operations will require disk access page faults to read data from virtual memory and negatively affect performance.
3、Page Faults
分析 db.serverStatus() 輸出的 extra_info 部分:
"extra_info" : { "note" : "fields vary by platform", "heap_usage_bytes" : 62941696, "page_faults" : 40 }
通常對大量數據的讀取會產生大量的page faults 會使mongodb 性能下降。解決辦法是優化sql或擴充內存。
4、連接數
分析 db.serverStatus() 輸出的 connections 部分:
"connections" : { "current" : 12, "available" : 1626, "totalCreated" : NumberLong(8014) } "globalLock" : { "totalTime" : NumberLong("240481182000"), "lockTime" : NumberLong(11670085), "currentQueue" : { "total" : 0, "readers" : 0, "writers" : 0 }, "activeClients" : { "total" : 0, "readers" : 0, "writers" : 0 } }
說明 :
globalLock.activeClients contains a counter of the total number of clients with active operations in progress or queued.
connections is a container for the following two fields:
current the total number of current clients that connect to the database instance.
available the total number of unused collections available for new clients.
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。