mongodb監控常用方法

來源:互聯網
上載者:User

標籤:each   訪問   涵蓋   ati   enc   profiling   9.1   read   分布   

列舉mongodb監控的常用命令

1.監控統計

mongostat 可用於查看當前QPS/記憶體使用量/串連數,以及多個shard的壓力分布

命令參考

./mongostat --port 27071  -u admin -p xxx --authenticationDatabase=admin --discover -n 30 3

參數說明
-discover 提供叢集中所有節點的狀態
-n 30 3 表示輸出30次,每次休眠3秒鐘

輸出樣本

                   insert query update delete getmore command  %dirty  %used flushes mapped vsize   res faults qr|qw  ar|aw netIn netOut conn    set repl                      time185.1.12.101:10001    499  4886   2042   1612     237   756|0     3.8   80.1       0        28.5G 19.1G    n/a   3|0    1|1    4m     7m 5545 shard0  PRI 2017-03-06T11:48:17+08:00

指標說明

指標名 說明
inserts/s 每秒插入數
query/s 每秒查詢數
update/s 每秒更新數
delete/s 每秒刪除數
getmore/s 每秒getmore數
command/s 每秒命令數,涵蓋了增刪改查和其他動作
dirty/% WriedTiger引擎參數,緩衝中無效資料百分比
used/% WriedTiger引擎參數,正在使用的緩衝百分比
flushs/s 每秒執行fsync將資料寫入硬碟次數
mapped/MB 所有的被mmap的資料量
vsize/MB 虛擬記憶體使用量
res/MB 實體記憶體使用量
faults/s 每秒訪問失敗數,與記憶體swap有關
qrqw 用戶端讀寫等待隊列數量,高並發時,一般隊列值會升高
araw 用戶端讀寫活躍個數
netIn 網路接收資料量
netOut 網路發送資料量
conn 當前串連數
set 所屬集合(分區)
repl 複製狀態(主節點/二級節點..)
time 時間戳記

官方說明
https://docs.mongodb.com/manual/reference/program/mongostat/

2.熱點操作

mongotop 用於查看當前佔用比例較高的DB操作,即熱點操作。

命令參考

./mongotop --port 10001  -u admin -p xxx --authenticationDatabase=admin

輸出樣本

    ns                  total   read    write   2017-03-20T15:22:36+08:00    nscl.T_De**ata      407ms   266ms   140ms                                 nscl.T_OAUT**EN     251ms   242ms   8ms                                 nscl.T_Subs**tion   180ms   180ms   0ms                                 nscl.T_De**istory   61ms    0ms     61ms                             

官方說明
https://docs.mongodb.com/manual/reference/program/mongotop/

3.慢操作檢測

profile是mongodb實現慢操作檢測的模組,官方說明

串連shell(使用root)

./mongo --port 10001  -u root -p xxx --authenticationDatabase=adminuse admin

注意
profile操作必須串連mongod進程,而mongos無法執行此類操作

profile設定

db.setProfilingLevel(0) 不輸出慢查詢db.setProfilingLevel(1,100) 統計慢查詢,100ms是閾值db.setProfilingLevel(2) 統計所有操作db.getProfilingLevel()

查詢慢查詢

db.system.profile.find().limit(10).sort( { ts : -1 } ).pretty() db.system.profile.find().limit(10).sort( { millis : -1 } ).pretty()

查詢當前操作

db.currentOp()
  • 範例-查詢等待鎖的增刪改查

    db.currentOp(   { "waitingForLock" : true, $or: [    { "op" : { "$in" : [ "insert", "update", "remove" ] } },    { "query.findandmodify": { $exists: true } }]   })
  • 範例-查詢活躍query操作

    db.currentOp(true).inprog.forEach(   function(opDoc){ if(!opDoc.active && opDoc.op=='query')    printjson(d) } )

    currentOp更多說明

4. 集合狀態分析

資料庫狀態

db.stats()->{   "db" : "test",           //當前資料庫   "collections" : 3,       //集合數量   "objects" : 165606718,   //對象數量   "avgObjSize" : 381,      //對象平均大小   "dataSize" : 63142130610, //所有資料總大小   "storageSize" : 16384,    //資料占磁碟大小   "numExtents" : 3,   "indexes" : 479,          //索引數   "indexSize" : 8011636736, //索引大小   "fileSize" : 201326592    //預分配給資料庫的檔案大小 } 

集合狀態

db.xxx.stats()->   ...    "sharded" : true,      //是否分區    "capped" : false,      //是否限制大小    "ns" : "nscl.T_BUSINESS_LOG",    "count" : 26541837,         //表數量    "size" : 14991828070,       //表大小    "storageSize" : 3615076352, //占磁碟大小    "totalIndexSize" : 2640109568, //索引大小    "avgObjSize" : 564.8376210734773,    "nindexes" : 6,    "nchunks" : 374         //chunk數量   ...

mongodb監控常用方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.