mtools工具介绍使用(一)

一、mtools工具安装

mtools工具安装包下载链接,可获取最新版本安装包进行下载:

https://github.com/rueckstiess/mtools/tags

1、python3环境部署,CentOS 7环境下默认的python版本为2.7,mtools工具需要依赖python3的环境

# yum install python3
# python3 --version

2、安装mtools工具

# wget -c https://github.com/rueckstiess/mtools/archive/refs/tags/v1.6.4.tar.gz
# tar xf v1.6.4.tar.gz -C /usr/local/
# cd /usr/local/mtools-1.6.4/
# python3 setup.py install

3、安装成功,mtools所有的工具默认安装在 /usr/local/bin/ 目录下

二、mloginfo 日志统计工具

1、查看日志基本信息

使用方法:

  • mloginfo [logfile]
# mloginfo config.log
     source: config.log
       host: sdw1:27002
      start: 2021 Apr 04 20:46:52.351
        end: 2021 May 04 08:12:15.888
date format: iso8601-local
   timezone: UTC +0800
     length: 3417
     binary: mongod
    version: 4.0.22
    storage: wiredTiger

2、查看日志消息类型统计分析信息

遍历日志文件,根据消息类型进行分组,并按照统计数的降序进行排序。

使用方法:

  • mloginfo [logfile] --distinct
# mloginfo config.log --distinct
DISTINCT

    1551  Connecting to
      25  connection accepted from ... # ... ( ... now open)
      25  Successfully authenticated as principal ... on
      23  received client metadata from ... :
      16  Successfully connected to ... ( ... connections now open to ... with a ... second timeout)
      10  end connection ... ( ... now open)
       9  Ending idle connection to host ... because the pool meets constraints; ... connections to that host remain open

3、查看日志连接数统计信息

根据IP对所有对该mongodb实例的打开/关闭链接进行统计。

使用方法:

  • mloginfo [logfile] --connections
# mloginfo config.log --connections
CONNECTIONS
     total opened: 1484
     total closed: 1475
    no unique IPs: 4
socket exceptions: 1

172.16.104.12    opened: 869       closed: 869
172.16.104.14    opened: 456       closed: 450
172.16.104.13    opened: 153       closed: 150
127.0.0.1        opened: 6         closed: 6

4、查看日志事物统计信息

针对MongoDB 4 以上的版本,可对事物的一些基本信息以及事物持续时间等信息进行统计。

使用方法:

  • mloginfo [logfile] --transaction
  • mloginfo [logfile] --transaction --tsort duration
TRANSACTION

DATETIME                       TXNNUMBER       AUTOCOMMIT      READCONCERN     TIMEACTIVEMICROS    TIMEINACTIVEMICROS   DURATION

2019-06-18T12:31:03.180+0100           1         false         "snapshot"                 11142                     3   7
2019-03-18T12:31:03.180+0100           2         false         "snapshot"                 11143                     4   6
2019-07-18T12:31:03.180+0100           3         false         "snapshot"                 11144                     3   4
2019-08-18T12:31:03.180+0100           4         false         "snapshot"                 11145                     4   7
2019-06-18T12:31:03.180+0100           5         false         "snapshot"                 11146                     3   3

5、查看日志游标统计信息

如果捕获的游标超过事务超时,则输出信息(事务的时间戳、游标ID、获取游标的时间)

使用方法:

  • mloginfo [logfile] --cursors
CURSOR

DATETIME                            CURSORID    REAPEDTIME

2019-06-14 12:31:04.180000+01:00    abc1        2019-06-18 12:31:04.180000+01:00
2019-06-14 12:31:04.180000+01:00    abc2        2019-06-18 12:31:06.180000+01:00
2019-06-14 12:31:04.180000+01:00    abc3        2019-06-18 12:31:08.180000+01:00

6、查看日志慢事物统计信息

输出关于慢事务的存储统计信息。

使用方法:

  • mloginfo [logfile] --storagestats
STORAGE STATISTICS

namespace                 operation    bytesRead    bytesWritten    timeReadingMicros    timeWritingMicros

config.system.sessions    update       None         None            None                 None
local.myCollection        insert       None         None            None                 None
local.myCollection        update       None         None            None                 None
local1.myCollection       insert       None         None            None                 None
invoice-prod.invoices     insert       12768411     22233323        86313                12344
invoice-prod.invoices     insert       12868411     22233323        86313                12344

7、查看分片信息

可查看分片的配置信息、错误信息、数据迁移信息等

使用方法:

  • mloginfo [logfile] --sharding
  • mloginfo [logfile] --sharding --errors
  • mloginfo [logfile] --sharding --migrations
SHARDING

Overview:

  The role of this node: (shard)
  Shards:
    shard1: 172.16.104.12:27001,172.16.104.13:27001,172.16.104.14:27001
    shard2: 172.16.104.12:27002,172.16.104.13:27002,172.16.104.14:27002
    shard3: 172.16.104.12:27003,172.16.104.13:27003,172.16.104.14:27003
    shard3: 172.16.104.12:27003,172.16.104.13:27003,172.16.104.14:27003
  CSRS:
    configs: 172.16.104.12:21000,172.16.104.13:21000,172.16.104.14:21000

to show sharding errors/warnings, run with --errors.

to show chunk migrations/splits, run with --migrations.

8、查看复制集群状态改变信息

输出有关每个检测到的复制集状态更改的信息。

使用方法:

  • mloginfo [logfile] --rsstate
RSSTATE
date               host                   state/message

Apr 04 20:48:18    172.16.104.14:27001    STARTUP
Apr 04 20:48:18    172.16.104.13:27001    STARTUP
Apr 04 20:48:21    172.16.104.14:27001    SECONDARY
Apr 04 20:48:21    172.16.104.13:27001    SECONDARY
Apr 14 18:49:39    172.16.104.13:27001    RS_DOWN
Apr 14 18:49:53    172.16.104.13:27001    SECONDARY
Apr 14 18:51:57    172.16.104.13:27001    RS_DOWN
Apr 14 18:52:07    172.16.104.13:27001    SECONDARY
Apr 14 18:59:03    172.16.104.13:27001    RS_DOWN
Apr 14 18:59:11    172.16.104.13:27001    SECONDARY
Apr 19 20:04:05    172.16.104.13:27001    RS_DOWN
Apr 19 20:04:41    172.16.104.13:27001    SECONDARY
Apr 19 20:15:23    172.16.104.13:27001    RS_DOWN
Apr 19 20:15:29    172.16.104.13:27001    SECONDARY
Apr 19 20:18:13    172.16.104.13:27001    RS_DOWN
Apr 19 20:18:21    172.16.104.13:27001    SECONDARY
May 04 08:12:15    172.16.104.13:27001    PRIMARY

9、查看重启服务信息

输出服务重启信息。

使用方法:

  • mloginfo [logfile] --restarts
RESTARTS
   Apr 04 20:46:41 version 4.0.22

10、语句的执行次数、耗时统计信息

输出日志中执行语句的分析信息,可报错语句类型、匹配模式、执行次数、耗时分析,可根据指定字段进行排序展示。

使用方法:

  • mloginfo [logfile] --queries
  • mloginfo [logfile] --queries --rounding 2
  • mloginfo [logfile] --queries --sort count
  • mloginfo [logfile] --queries --sort sum
QUERIES

namespace                  operations    pattern                                        count    min (ms)    max (ms)    mean (ms)       95%-ile (ms)    sum (ms)        allowDiskUse

serverside.scrum_master    update        {"datetime_used": {"$ne": 1}}                     20       15753       17083        16434          1.8          328692          True
serverside.django_session  find          {"_id": 1}                                       562         101        1512          317          2.0          178168          False
serverside.user            find          {"_types": 1, "emails.email": 1}                 804         101        1262          201          1.0          162311          False
local.slaves               find          {"_id": 1, "host": 1, "ns": 1}                   131         101        1048          310          0.0          40738           True
serverside.email_alerts    update        {"_types": 1, "email": 1, "pp_user_id": 1}        13         153       11639         2465          0.0          32053           None
serverside.sign_up         update        {"_id": 1}                                        77         103         843          269          1.8          20761           None
serverside.user_credits    remove        {"_id": 1}                                         6         204         900          369          1.3          2218            None
serverside.counters        remove        {"_id": 1, "_types": 1}                            8         121         500          263          2.1          2111            True
serverside.auth_sessions   update        {"session_key": 1}                                 7         111         684          277          1.0          1940            True
serverside.credit_card     update        {"_id": 1}                                         5         145         764          368          0.0          1840            True
serverside.email_alerts    remove        {"_types": 1, "request_code": 1}                   6         143         459          277          1.3          1663            False
serverside.user            find          {"_id": 1, "_types": 1}                            5         153         427          320          1.9          1601            False
serverside.user            update        {"emails.email": 1}                                2         218         422          320          0.7          640             True
serverside.user            update        {"_id": 1}                                         2         139         278          208          0.4          417             True
serverside.auth_sessions   update        {"session_endtime": 1, "session_userid": 1}        1         244         244          244          0.2          244             False
serverside.game_level      find          {"_id": 1}                                         1         104         104          104          0.1          104             None

三、mlogfilter 日志过滤工具

1、用法

usage: mlogfilter [-h] [--version] [--no-progressbar] [--verbose]
                  [--shorten [LENGTH]] [--exclude] [--human] [--json]
                  [--markers [MARKERS [MARKERS ...]]] [--timezone [N [N ...]]]
                  [--timestamp-format {none,ctime-pre2.4,ctime,iso8601-utc,iso8601-local}]
                  [--from [FROM [FROM ...]]] [--to [TO [TO ...]]]
                  [--fast [FAST]] [--component [CM [CM ...]]]
                  [--level [LL [LL ...]]] [--namespace [NS [NS ...]]]
                  [--operation [OP [OP ...]]] [--thread [THREAD [THREAD ...]]]
                  [--pattern PATTERN] [--command [COMMAND [COMMAND ...]]]
                  [--planSummary [PS [PS ...]]] [--mask MASK]
                  [--mask-size MASK_SIZE] [--mask-center {start,end,both}]
                  [--slow [SLOW]] [--scan] [--transactions]
                  [--word [WORD [WORD ...]]]
                  [logfile [logfile ...]]

2、重点参数解释

参数含义
–namespace按照命名空间进行过滤
–operation按照操作类型进行过滤
–thread按照线程名称进行过滤
–pattern根据超足匹配模式进行过滤
–slow MS, --fast MS返回较指定时间慢/快的操作
–scan查看全文档扫描的操作
–word WORD [WORD …]根据关键字进行过滤
–from FROM [FROM …], --to TO [TO …]根据指定时间进行切片

3、示例

1)查看日志最后20min日志

# mlogfilter config.log --from "end -20min"

2)查看最近1小时日志

# mlogfilter config.log --from "end -2h" --to +1h

3)查看指定时间后1个小时的日志

# mlogfilter config.log --from Apr 6 0:00 --to "+1h"
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值