標籤:zabbix監控mongodb配置
本文主要介紹zabbix監控mongodb的配置。
zabbix監控mongodb需要自訂指令碼去監控,指令碼可以傳入多個參數。
原理:通過mongodb用戶端串連命令,過濾出db.serverStatus()輸出的資訊。
一、建立監控資料擷取指令碼
1.指令碼內容:
#cat check_mongodb.sh#!/bin/bash## mongodb status# db.serverStatus().ok# memory status# Physical memory: db.serverStatus().mem.resident# Virtual memory: db.serverStatus().mem.virtual# opcounters status# insert: db.serverStatus().opcounters.insert# query: db.serverStatus().opcounters.query# update: db.serverStatus().opcounters.update# delete: db.serverStatus().opcounters.delete# connections status# current connections: db.serverStatus().connections.currentMONGODBPATH="/usr/local/mongodb3.2.1/bin/mongo"HOST="127.0.0.1"PORT="$1"MONGODB_PA="$MONGODBPATH ${HOST}:${PORT}" if [ $# == 3 ];then result=$(/bin/echo "db.serverStatus().$2.$3" | $MONGODBPATH ${HOST}:${PORT} --quiet) echo $resultelif [ $# == 2 ];then result=$(/bin/echo "db.serverStatus().$2" | $MONGODBPATH ${HOST}:${PORT} --quiet) echo $resultelse echo "Usage:$0 PORT mem resident"fi
2.指令碼使用
存放位置:/usr/local/zabbix/etc/scripts
功能:
(1).指令碼能接受三個參數傳入,監控mongodb記憶體使用量情況、用戶端串連數、dml動作陳述式情況等
(2).指令碼能接受二個參數傳入,監控mongodb是否線上
二、修改agent設定檔
1.修改zabbix_agentd.conf
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
2.在zabbix_agentd.conf.d下定義監控mongodb的key
#cat mongodb_stats.confUserParameter=mongodb_stats[*],/usr/local/zabbix/etc/scripts/check_mongodb.sh $1 $2 $3
3.重啟agent服務
三、在web介面建立監控項
mongodb執行個體連接埠定義成主機宏,具體宏操作參考:http://hnr520.blog.51cto.com/4484939/1852655
1.建立監控mongodb是否線上items
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/87/43/wKioL1fZL3qRzAbFAACC9xZt6_c887.png-wh_500x0-wm_3-wmp_4-s_36355605.png" title="01.png" alt="wKioL1fZL3qRzAbFAACC9xZt6_c887.png-wh_50" />
索引值:mongodb_stats[{$MONGODB_PORT_TEST},ok]
2.建立監控mongodb記憶體使用量情況itmes
650) this.width=650;" src="http://s5.51cto.com/wyfs02/M01/87/43/wKioL1fZL4eSgbvCAACLOtWsfC0973.png-wh_500x0-wm_3-wmp_4-s_2277463453.png" title="02.png" alt="wKioL1fZL4eSgbvCAACLOtWsfC0973.png-wh_50" />
索引值:mongodb_stats[{$MONGODB_PORT_TEST},mem,resident]
注意:採集到資料單位為MB,單位使用B,因此需要定義1024*1024倍數,否則當記憶體使用量超過GB時沒法顯示出GB
3.建立監控mongodb用戶端串連數items
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M00/87/45/wKiom1fZL5XCTzbIAACDVb68i9w467.png-wh_500x0-wm_3-wmp_4-s_2441375826.png" title="03.png" alt="wKiom1fZL5XCTzbIAACDVb68i9w467.png-wh_50" />
索引值:mongodb_stats[{$MONGODB_PORT_TEST},connections,current]
4.建立監控dml語句相關資訊items
650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/87/45/wKiom1fZL6zhyxmhAACGy0uBGj8184.png-wh_500x0-wm_3-wmp_4-s_2506454900.png" title="04.png" alt="wKiom1fZL6zhyxmhAACGy0uBGj8184.png-wh_50" />
索引值:mongodb_stats[{$MONGODB_PORT_TEST},opcounters,insert]
注意:通過db.serverStatus().opcounters監控到資料是服務啟動以來總的數量,因此儲存實值型別需要修改成差量
其他幾個query、delete、update類型建立
四、查看資料
選擇監測中---->最新資料---->選擇相應過濾條件
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M00/87/43/wKioL1fZL7uxAa5PAADlolNypbI485.png-wh_500x0-wm_3-wmp_4-s_3252373290.png" title="05.png" alt="wKioL1fZL7uxAa5PAADlolNypbI485.png-wh_50" />
五、建立mongodb opcounters資訊圖形
選擇配置---->主機---->選擇mongodb主機---->圖形
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M01/87/45/wKiom1fZL8rzsmmUAACkX_Cz2P8482.png-wh_500x0-wm_3-wmp_4-s_3406130718.png" title="06.png" alt="wKiom1fZL8rzsmmUAACkX_Cz2P8482.png-wh_50" />
650) this.width=650;" src="http://s5.51cto.com/wyfs02/M01/87/43/wKioL1fZL9nCJOWrAAJMvMuPmSQ982.png-wh_500x0-wm_3-wmp_4-s_952953082.png" title="07.png" alt="wKioL1fZL9nCJOWrAAJMvMuPmSQ982.png-wh_50" />
本文出自 “linux之路” 部落格,請務必保留此出處http://hnr520.blog.51cto.com/4484939/1852833
Zabbix監控mongodb配置