当前位置: 首页 > 工具软件 > Mtools > 使用案例 >

MongoDB之Mtools工具

潘驰
2023-12-01

项目地址

Github地址

 

安装步骤

  • Mtools工具是用Python写的,所以首先环境中要安装Python,目前支持版本 2.6.x 和 2.7.x;
  • 安装pip,pip 是“A tool for installing and managing Python packages.”;
  • wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
    
    tar -xzvf pip-1.5.4.tar.gz
    
    cd pip-1.5.4
    
    python setup.py install
  • 安装setuptools,python下的setuptools带有一个easy_install的工具,在安装python的每三方模块、工具时很有用,也很方便
  • wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-12.0.3.tar.gz#md5=f07e4b0f4c1c9368fcd980d888b29a65
    
    tar -zxvf setuptools-12.0.3.tar.gz
    
    cd setuptools=12.0.3
    
    python setup.py install
  • 最简单的安装Mtools工具的方法:
  • pip install mtools

 

工具简介

        mlogfileter可以简单理解为日志的过滤器

        1.通过Mlogfilter 列出日志文件中所有的slow log(以json格式输出)

  • mlogfilter mongod.log-20150721 --slow --json
    

        2.将通过mlogfilter输出的所有slow log入库

  • mlogfilter mongod.log-20150721 --slow --json |mongoimport -d test -c mycoll
    

        3.通过mlogfilter查询日志中某个表的slow log(超过100ms的)

  • mlogfilter --namespace xxx.xx --slow 100 mongod.log-20150721

        mloginfo可以过滤总结出slow query的情况,以及为日志中各类最常常出现情况进行统计

        1.通过mloginfo统计日志中各类信息的distinct

  • mloginfo mongod.log-20150721 --distinct
    

        2.通过mloginfo统计日志中connections的来源情况

  • mloginfo mongod.log-20150721 --connections
    

        3.通过mloginfo查看日志中所记录的复制集状态变更(如果有的话)

  • mloginfo mongod.log-20150721 --rsstate
    

        4.通过mloginfo统计查看日志中慢查询的分类

  • mloginfo --queries mongod.log-20150721

        用不同类型的图将日志文件可视化(需要安装matplotlib)

        1.通过mplotqueries进行慢查询散点分布图绘制

  • mplotqueries mongod.log-20150721 --output-file 01-2.png
    

        2.通过mplotqueries进行慢查询散点分布图绘制,且只返回前10个

  • mplotqueries mongod.log-20150721 --output-file 01-3.png --group-limit 10
    

        3.上一个图中,我们可以发现底部的数据难以看清,我们可以使用对数模式

  • mplotqueries mongod.log-20150721 --output-file 01-4.png --logscale --group-limit 10
    

        4.仅看日志中某一个表的慢查询散点分布情况

  • mlogfilter mongod.log-20150721 --namespace xx.xxx |mplotqueries --output-file 01-5.png
    

        5.通过mplotqueries来对日志中的慢查询进行操作类型分布

  • mplotqueries mongod.log-20150721 --group operation --output-file 01-6.png
    

        6.通过mplotqueries对日志中的慢查询进行扫表情况绘图

  • mplotqueries mongod.log-20150721 --type nscanned/n --output-file 01-7.png
    

        7.自定义y轴内容,这里以w为例(nscanned, nupdated,ninserted, ntoreturn, nreturned, numYields, r (读锁), w (写锁))

  • mplotqueries mongod.log-20150721 --yaxis w --output-file 01-8.png
    

        8.通过mplotqueries对连接情况进行分析,时间块单位1800(30min)

  • mplotqueries mongod.log-20150721 --type connchurn --bucketsize 1800 --output-file 01-9.png
    

        9.通过mlogfileter过滤出xx.xxx的update,然后每30min时间块 以_id分布(这里可以引申为任何条件支持正则)

  • mlogfilter mongod.log-20150721 --operation update --namespace xx.xxx | mplotqueries --type histogram --group "_id:([^,}]*)" --bucketsize 1800 --output-file 01-10.png --group-limit 20
    

        10.查看每小时的insert情况

  • mlogfilter mongod.log-20150721 --operation insert | mplotqueries --type histogram --bucketsize 3600 --output-file 01-11.png
    

        11.对日志中的slow log进行分布绘图,(出现间隔超过10min时,显示间隔)

  • mplotqueries mongod.log-20150721 --type range --group operation --gap 600 --output-file 01-12.png
    

        12.对日志中的事件进行绘图(事件图,显示出各类事件出现的时间位置等)

  • grep "getlasterror" mongod.log-20150721 | mplotqueries --type event --output-file 01-13.png
    

        13.通过log进行复制集状态的查看。(会绘制出复制集状态变动图形)

  • mplotqueries mongod.log-20150721 --type rsstate --output-file 01-14.png

转载于:https://my.oschina.net/huangjicheng/blog/716296

 类似资料: