大家好,我是E叔,好久不见,我来挖一个新坑《MongoDB干货系列》。
本文第一发分享,也是我将在9月中上海用户组见面会上的分享的先行版部分内容,希望有所帮助。
监控与troubleshooting永远是任何数据库最需要关注的地方之一。
任何数据库的DBA都应该对数据库情况进行定期的巡检,以清楚了解数据库的运行情况,健康状况,隐患等等。
本文主要讲述的是如何使用Mtools工具对MongoDB数据库进行巡检。
通过mtools并结合监控数据,如MMS,ZABBIX,或者自行绘制的监控图形,能够较好的对mongodb的运行情况,健康状况进行检查,并排除隐患。且在troubleshooting的时候也能提供很好的帮助。
Mtools是由MongoDB Inc 官方工程师所写,设计之初是为了方便自己的工作,但是随着MongoDB用户的增加,越来越多的朋友也开始使用Mtools,也越来越感受到Mtools带来的便捷。
Github地址如下:
Mtools github地址
Mtools主要有以下组件:
mlogfilter mloginfo mplotqueries mlogvis mlaunch mgenerate
在此就不一一介绍了,本文中主要使用到的是 mlogfilter,mloginfo和mplotqueries.
首先,我们来简单介绍下 mlogfilter,mloginfo和mplotqueries。
mlogfileter我们可以简单理解为日志的过滤器,参数如下,就不一一简介了
mlogfilter [-h] [--version] logfile [logfile ...]
[--verbose] [--shorten [LENGTH]]
[--human] [--exclude] [--json]
[--timestamp-format {ctime-pre2.4, ctime, iso8601-utc, iso8601-local}]
[--markers MARKERS [MARKERS ...]] [--timezone N [N ...]]
[--namespace NS] [--operation OP] [--thread THREAD]
[--slow [SLOW]] [--fast [FAST]] [--scan]
[--word WORD [WORD ...]]
[--from FROM [FROM ...]] [--to TO [TO ...]]
mloginfo可以过滤总结出slow query的情况,以及为日志中各类最常常出现情况进行统计,参数如下:
mloginfo [-h] [--version] logfile
[--verbose]
[--queries] [--restarts] [--distinct] [--connections] [--rsstate]
mplotqueries相对复杂一些,功能是可以根据需求画图,以便更直观的找出问题或者隐患所在。
具体用法参见github中的详情页,为了方便大家阅读,我也在这转发一个小伙伴翻译的中文版本
mplotqueries 中文翻译
特此感谢 吕明明的翻译。
参数如下:
mplotqueries [-h] [--version] logfile [logfile ...]
[--group GROUP]
[--logscale]
[--type {nscanned/n,rsstate,connchurn,durline,histogram,range,scatter,event} ]
[--overlay [ {add,list,reset} ]]
[additional plot type parameters]
由于本文主要讲述的是通过Mtools来辅助我们定期巡检,且主打“干货”,我将在下面直接进行一系列的使用分享。
mlogfilter mongod.log-20150721 --slow --json
mlogfilter mongod.log-20150721 --slow --json |mongoimport -d test -c mycoll
mlogfilter --namespace xxx.xx --slow 100 mongod.log-20150721
mloginfo mongod.log-20150721 --distinct
mloginfo mongod.log-20150721 --connections
mloginfo mongod.log-20150721 --rsstate
mloginfo --queries mongod.log-20150721
mplotqueries mongod.log-20150721 --output-file 01-2.png
mplotqueries mongod.log-20150721 --output-file 01-3.png --group-limit 10
mplotqueries mongod.log-20150721 --output-file 01-4.png --logscale --group-limit 10
mlogfilter mongod.log-20150721 --namespace xx.xxx |mplotqueries --output-file 01-5.png
mplotqueries mongod.log-20150721 --group operation --output-file 01-6.png
mplotqueries mongod.log-20150721 --type nscanned/n --output-file 01-7.png
mplotqueries mongod.log-20150721 --yaxis w --output-file 01-8.png
mplotqueries mongod.log-20150721 --type connchurn --bucketsize 1800 --output-file 01-9.png
mlogfilter mongod.log-20150721 --operation update --namespace xx.xxx | mplotqueries --type histogram --group "_id:([^,}]*)" --bucketsize 1800 --output-file 01-10.png --group-limit 20
mlogfilter mongod.log-20150721 --operation insert | mplotqueries --type histogram --bucketsize 3600 --output-file 01-11.png
mplotqueries mongod.log-20150721 --type range --group operation --gap 600 --output-file 01-12.png
grep "getlasterror" mongod.log-20150721 | mplotqueries --type event --output-file 01-13.png
mplotqueries mongod.log-20150721 --type rsstate --output-file 01-14.png
overlay参数可以将多组图进行重叠,便于troubleshooting时候的快速分析。 建立overlay仅需加参数--overlay 查看overlay可以使用--overlay list 清空overlay可以使用--overlay reset
有了这些数据我们如何进行分析呢?
首先需要知道,一切异于常态的状态都是值得关注的,如8图中有一些点完全高于其他点,这就是可以重点关注从此下手进行调查。
再者mloginfo查询出的slow log 类型结合我们mongo本身记录的 profile 也可以一起对业务语句进行很好的分析,查询执行计划,并进行优化。
结合mtools所绘的图片,并将系统数据(cpu,io,mem,进程资源情况)的数据监控图进行重叠比较,也能够为troubleshooting提供很好的帮助。
以上便是本次分享的内容了,如果有什么问题欢迎联系我,希望有所帮助。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29096438/viewspace-2156401/ ,如需转载,请注明出处,否则将追究法律责任。