Zabbix监控MongoDB性能状态

小柒助手 Zabbix32152,5915字数 1405阅读4分41秒阅读模式

Zabbix监控MongoDB性能的原理:通过echo "db.serverStatus()" | mongo admin 来查看mongodb的状态。

Zabbix监控MongoDB性能,主要监控以下项目:文章源自小柒网-https://www.yangxingzhen.cn/5883.html

- 内存使用情况文章源自小柒网-https://www.yangxingzhen.cn/5883.html

- 连接数文章源自小柒网-https://www.yangxingzhen.cn/5883.html

- 锁文章源自小柒网-https://www.yangxingzhen.cn/5883.html

- 刷新写操作到磁盘文章源自小柒网-https://www.yangxingzhen.cn/5883.html

- 每秒执行的查询,插入,删除,更新等操作次数文章源自小柒网-https://www.yangxingzhen.cn/5883.html

- 每秒访问的索引次数,每秒命中索引的次数文章源自小柒网-https://www.yangxingzhen.cn/5883.html

- MongoDB产生的总的页面错误数量文章源自小柒网-https://www.yangxingzhen.cn/5883.html

- MongoDB的网络流量状况文章源自小柒网-https://www.yangxingzhen.cn/5883.html

监控操作步骤:
文章源自小柒网-https://www.yangxingzhen.cn/5883.html

1、编写脚本

2、上传脚本到指定位置

3、修改zabbix_agent配置文件

4、zabbix_server的WEB界面导入模版

5、主机关联

1)编辑zabbix_agent配置文件,添加以下内容

[root@localhost ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf

UserParameter=Mongodb.state[*],/data/scripts/auto_detection_mongodb_state.sh $1
UserParameter=mongodb.status[*],/data/scripts/auto_detection_mongodb_status.sh $1
#保存退出

2)重启zabbix_agentd服务

[root@localhost ~]# service zabbix_agentd restart

3)下载脚本文件(获取监控值)

[root@localhost ~]# cd /data/scripts

[root@localhost scripts]# wget https://mirrors.yangxingzhen.com/shell/auto_detection_mongodb_status.sh

[root@localhost scripts]# wget https://mirrors.yangxingzhen.com/shell/auto_detection_mongodb_state.sh

[root@localhost scripts]# cat auto_detection_mongodb_status.sh

#!/bin/bash
# Description: zabbix ${DB_BIN}/mongodb monitor
# Note: Zabbix 4.0.7
# Date: 2019-7-31 21:20:39
# Verion: 1.0

DB_HOST=127.0.0.1
DB_PORT=27017
DB_BIN="/usr/local/mongodb/bin"

if [[ $# == 1 ]];then
case $1 in
	insert)
	echo "db.serverStatus().opcountersRepl" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "insert"|awk '{print $3}'|sed 's/,//'
	;;
	query)
	echo "db.serverStatus().opcountersRepl" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "query"|awk '{print $3}'|sed 's/,//'
	;;
	delete)
	echo "db.serverStatus().opcountersRepl" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "delete"|awk '{print $3}'|sed 's/,//'
	;;
	getmore)
	echo "db.serverStatus().opcountersRepl" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "getmore"|awk '{print $3}'|sed 's/,//'
	;;
	command)
	echo "db.serverStatus().opcountersRepl" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "command"|awk '{print $3}'|sed 's/,//'
	;;
	update)
	echo "db.serverStatus().opcountersRepl" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "update"|awk '{print $3}'|sed 's/,//'
	;;
	current)
	echo "db.serverStatus().connections"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "current"|awk '{print $4}'|sed 's/,//'
	;;
	available)
	echo "db.serverStatus().connections"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "available"|awk '{print $7}'|sed 's/,//'
	;;
	totalCreated)
	echo "db.serverStatus().connections"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "totalCreated"|awk '{print $10}'|sed 's/,//'
	;;
	total)
	echo "db.serverStatus().globalLock.activeClients"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "total"|awk '{print $4}'|sed 's/,//'
	;;
	readers)
	echo "db.serverStatus().globalLock.activeClients"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "readers"|awk '{print $7}'|sed 's/,//'
	;;
	writers)
	echo "db.serverStatus().globalLock.activeClients"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "writers"|awk '{print $10}'|sed 's/,//'
	;;
	deleted)
	echo "db.serverStatus().metrics.document"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "deleted"|awk -F '(' '{print $2}'|sed 's/),//'
	;;
	inserted)
	echo "db.serverStatus().metrics.document"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "inserted"|awk -F '(' '{print $2}'|sed 's/),//'
	;;
	returned)
	echo "db.serverStatus().metrics.document"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "returned"|awk -F '(' '{print $2}'|sed 's/),//'
	;;
	updated)
	echo "db.serverStatus().metrics.document"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "updated"|awk -F '(' '{print $2}'|sed 's/)//'
	;;
	totalTime)
	echo "db.serverStatus().globalLock"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "totalTime" |awk '{print $3}'|awk -F '"' '{print $2}'
	;;
	bytesIn)
	echo "db.serverStatus().network"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "bytesIn"|awk -F'(' '{print $2}'|sed 's/),//'
	;;
	bytesOut)
	echo "db.serverStatus().network"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "bytesOut"|awk -F'(' '{print $2}'|sed 's/),//'
	;;
	numRequests)
	echo "db.serverStatus().network"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "numRequests"|awk -F'(' '{print $2}'|sed 's/)//'
	;;
	mapped)
	echo "db.serverStatus().mem" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "mapped"|awk '{print $3}'|sed 's/,//'
	;;
	resident)
	echo "db.serverStatus().mem" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "mappedWithJournal"|awk '{print $3}'|sed 's/,//'
	;;
	virtual)
	echo "db.serverStatus().mem" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "virtual"|awk '{print $3}'|sed 's/,//'
	;;
	mappedWithJournal)
	echo "db.serverStatus().mem" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep -w "resident"|awk '{print $3}'|sed 's/,//'
	;;
	*)
	echo -e "\033[33mUsage: $0 {insert|query|delete|getmore|command|update|current|available|totalCreated|total|readers|writers|deleted|inserted|returned|updated|totalTime|bytesIn|bytesOut|numRequests||mapped|resident}\033[0m"
	exit 1
esac
else
	echo -e "\033[33mUsage: $0 {insert|query|delete|getmore|command|update|current|available|totalCreated|total|readers|writers|deleted|inserted|returned|updated|totalTime|bytesIn|bytesOut|numRequests||mapped|resident}\033[0m"
	exit 1
fi

[root@localhost scripts]# cat auto_detection_mongodb_state.sh

#!/bin/bash
# Description: zabbix ${DB_BIN}/mongodb monitor
# Note: Zabbix 4.0.7
# Date: 2019-7-31 21:01:22
# Verion: 1.0

DB_HOST="127.0.0.1"
DB_PORT="27017"
DB_BIN="/usr/local/mongodb/bin"

if [[ $# == 1 ]];then
case $1 in
	insert)
	echo "db.serverStatus().opcounters" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "insert"|awk '{print $3}'|sed 's/,//'
	;;
	query)
	echo "db.serverStatus().opcounters" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "query"|awk '{print $3}'|sed 's/,//'
	;;
	delete)
	echo "db.serverStatus().opcounters" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "delete"|awk '{print $3}'|sed 's/,//'
	;;
	getmore)
	echo "db.serverStatus().opcounters" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "getmore"|awk '{print $3}'|sed 's/,//'
	;;
	command)
	echo "db.serverStatus().opcounters" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "command"|awk '{print $3}'|sed 's/,//'
	;;
	update)
	echo "db.serverStatus().opcounters" |${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "update"|awk '{print $3}'|sed 's/,//'
	;;
	total)
	echo "db.serverStatus().globalLock.currentQueue"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "total"|awk '{print $4}'|sed 's/,//'
	;;
	readers)
	echo "db.serverStatus().globalLock.currentQueue"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "readers"|awk '{print $7}'|sed 's/,//'
	;;
	writers)
	echo "db.serverStatus().globalLock.currentQueue"|${DB_BIN}/mongo ${DB_HOST}:${DB_PORT}/admin |grep "writers"|awk '{print $10}'|sed 's/,//'
	;;
	*)
	echo -e  "\033[33mUsage: $0 {insert|query|delete|getmore|command|update|total|readers|writers}\033[0m"
	exit 1
esac
else
	echo -e  "\033[33mUsage: $0 {insert|query|delete|getmore|command|update|total|readers|writers}\033[0m"
	exit 1
fi
4)脚本授权

[root@localhost scripts]# chmod +x auto_detection_mongodb_status.sh

[root@localhost scripts]# chmod +x auto_detection_mongodb_state.sh

5)验证server端验证是否能获取agent端的key值

#使用zabbix_get命令获取key值

Zabbix监控平台配置

1、下载监控模板文件

模板附件下载:

2、导入Mongodb监控模板

进入后台->配置->模板->导入(右上角)->选择下载的模板文件->最后点击导入 。

至此Mongodb监控模板已经导入到Zabbix中。

3、关联模板

需要把Mongodb监控模板链接到你的监控主机上,进入后台->配置->点击你的主机->模板->选择刚才导入模板,点击添加,最后点击更新即可。

4、效果图展示

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
历史上的今天
7 月
31
Wechat
微信扫一扫,加我!
weinxin
我的微信
微信号已复制
微信公众号
微信扫一扫,关注我!
weinxin
我的公众号
公众号已复制
Zabbix最后更新:2022-11-23
小柒助手
  • 本文由 小柒助手 发表于 2019年7月31日 21:18:02
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.cn/5883.html
评论  32  访客  28  作者  4
    • andy
      andy 0

      魔板文件给下,楼主大大

      • chen
        chen 2

        楼主,下载模板不见了

        • chen
          chen 2

          真不错

          • sdf
            sdf 1

            导出vdv

            • sdf
              sdf 1

              很好

              • Assange
                Assange 4

                :wink: :wink: 再次评论~~

                • Assange
                  Assange 4

                  我的赞去哪里了~~~

                  • jack
                    jack 1

                    :wink: :wink:

                    • jack
                      jack 1

                      赞一下

                      • wind
                        wind 0

                        再赞一下!!!!!!!!!!!!!!!!!!

                        • 666
                          666 1

                          谢谢

                          • 666
                            666 1

                            nice,谢谢

                            • 依憐旳丶
                              依憐旳丶 2

                              写的太好了

                              • 1
                                1 0

                                谢谢分享

                                • nelson
                                  nelson 0

                                  谢谢分享

                                  • xxd
                                    xxd 0

                                    看看模板

                                    • 追梦
                                      追梦 0

                                      看看模板

                                      • 嗨咯啊哈哼
                                        嗨咯啊哈哼 0

                                        看看模板

                                        • 新手入门
                                          新手入门 0

                                          看看模板

                                          • 肥皂
                                            肥皂 0

                                            看看模板,谢谢

                                            • wuwuw
                                              wuwuw 0

                                              挺不错

                                              • lanlinlan
                                                lanlinlan 1

                                                模板链接都挂了

                                                • lanlinlan
                                                  lanlinlan 1

                                                  支持zabbix4吗 我感觉现在zabbix更新好快

                                                  • 浪子情缘
                                                    浪子情缘 0

                                                    不错

                                                  匿名

                                                  发表评论

                                                  匿名网友
                                                  :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

                                                  拖动滑块以完成验证