監控原理
在MongoDB服務器上可以通過shell命令echo "db.serverStatus()" | mongo admin來查看MongoDB的狀態。
[root@mongo163 ~]# echo "db.serverStatus()" | mongo admin MongoDB shell version: 1.8.1 connecting to: admin ->db.serverStatus() { "host" : "mongo163", "version" : "1.8.1", "process" : "mongod", "uptime" : 451749, "uptimeEstimate" : 281868, "localTime" : ISODate("2011-05-23T07:42:01.990Z"), "globalLock" : { "totalTime" : 451749911134, "lockTime" : 50304542058, "ratio" : 0.11135484660467028, "currentQueue" : { "total" : 0, "readers" : 0, "writers" : 0 }, "activeClients" : { "total" : 1, "readers" : 1, "writers" : 0 } }, "mem" : { "bits" : 64, "resident" : 21790, "virtual" : 63679, "supported" : true, "mapped" : 58328 },
"connections" : { "current" : 3, "available" : 19997 }, "extra_info" : { "note" : "fields vary by platform", "heap_usage_bytes" : -1519420976, "page_faults" : 179599 }, "indexCounters" : { "btree" : { "accesses" : 2324660, "hits" : 2324619, "misses" : 41, "resets" : 0, "mi***atio" : 0.00001763698777455628 } }, "backgroundFlushing" : { "flushes" : 7528, "total_ms" : 64933966, "average_ms" : 8625.659670563231, "last_ms" : 10583, "last_finished" : ISODate("2011-05-23T07:41:10.754Z") }, "cursors" : { "totalOpen" : 1, "clientCursors_size" : 1, "timedOut" : 65 }, "network" : { "bytesIn" : 31194795281, "bytesOut" : 24269782063, "numRequests" : 254375763 }, "repl" : { "ismaster" : true }, "opcounters" : { "insert" : 38301524, "query" : 1770, "update" : 35909520, "delete" : 10486310, "getmore" : 42387, "command" : 169619319 }, "asserts" : { "regular" : 0, "warning" : 0, "msg" : 0, "user" : 6, "rollovers" : 0 }, "writeBacksQueued" : false, "note" : "run against admin for more info", "ok" : 1 |
因此可以考慮使用zabbix的UserParameter自定義監控,對MongoDB進行監控
添加MongoDB監控
1、zabbix客戶端配置文件zabbix_agentd.conf文件,添加如下內容:
UserParameter=MongoDB.Status[*],/bin/echo "db.serverStatus().$1" | /usr/local/sbin/mongo admin | grep "$2"|awk -F: '{print $$2}'|awk -F, '{print $$1}' |
2、重新啓動zabbix客戶端
/etc/init.d/zabbix_agentd restart |
添加編寫MongoDB監控模板
1、創建模板:
系統配置->模板,點擊右上角的“創建模板”,添加“MongoDB Moniting”模板
2、添加監控項:
系統配置->“MongoDB Moniting”模板->監控項,點擊右上角的“Create Item”,創建監控項:
3、添加圖形顯示:
系統配置->“MongoDB Moniting”模板->圖形顯示,點擊右上角的“創建圖形”,創建相應圖形:
應用MongoDB監控模板
1、在裝有MongoDB的服務器上應用該模板:
系統配置->主機,選擇一臺裝有MongoDB的服務器,在右邊的“Linked templates”,添加MongoDB監控模板,然後保存
2、MongoDB監控最新數據:
創建MongoDB服務器配置圖表
1、系統配置->配置圖表,點擊右上角的“create screen”,創建圖表。
2、圖表中添加如下內容:
MongoDB服務器的
(1) CPU使用情況
(2) Load Average服務器負載情況
(3) Memory服務器內存使用情況
(4) MongoDB Background Fluhes
(5) MongoDB Commands
(6) MongoDB Current Connetctions
(7) MongoDB Index Ops
(8) MongoDB Memory
(9) MongoDB Networks