Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use Mtools to analyze MongoDB log files

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

An introduction to Mtools

Mtools is a set of scripts used to parse and filter MongoDB log files. Mtools includes the following tools:

Mlogfilter can cut log files according to time, filter slow queries, etc.

Mloginfo returns log file information, such as start and end times

Mplotqueries makes a view display of log files

Mlogvis creates a custom html file for interactive presentation

Mlaunch quickly builds a local test environment, including replication collection slicing system

Mtools is written in python and requires python2.6 or python2.7. Currently it is not compatible with python3.

2. Use of Mtools

1. Install mtools

You can install mtools directly using pip

Yum install python-devel

Pip install numpy

Pip install python-matplotlib

Pip install mtools

Or download and install directly

Wget https://pypi.python.org/packages/25/fe/c9375c462c9f0592407695bb5ce784866ce7b5336b8d66141e1f3250cf1f/mtools-1.2.2.tar.gztar zxvf mtools-1.2.2.tar.gzpython setup.py install

2.mlogfilter

Mlogfilter is used to parse logs. If there are multiple log files, mlogfilter merges according to timestamp.

Mlogfilter mongod.log-- slow-- json | mongoimport-d test-c mycoll

Analyze slow queries and export them in json format and import them into the mycoll collection of the test library

Mlogfilter / opt/logs/mongodb/*.log-slow-json

To view a slow query of a collection of a library, slow can specify how many milliseconds the slow query time is.

Mlogfilter mongod.log-namespace admin.\ $cmd-slow 1000

To view a slow query of a certain operation type, only one operation type can be specified at a time, which can be query,insert,update,delete,command,getmore.

Mlogfilter / opt/logs/mongodb/*.log-- slow 1000-- namespace order.bill-- operation query

According to the view slow query of a certain thread

Mlogfilter / opt/logs/mongodb/*.log-slow 1000-namespace order.bill-operation query-thread conn1317475

-- parttern P queries logs based on matching criteria

Mlogfilter mongod.log-- pattern'{"_ id": 1, "host": 1, "ns": 1}

It should be noted here that the field name must be enclosed in double quotation marks

Filter logs based on keywords

Mlogfilter mongod.log-word assert warning error

Log search based on time range

Return all September logs

Mlogfilter mongod.log-from Sep

Return to the log from 5 minutes ago

Mlogfilter mongod.log-from "now-5min"

Return to the log from 00:00:00 to 02:00:00 that day

Mlogfilter mongod.log-from today-to + 2hours

Return to the log that started at 9:30 for the day

Mlogfilter mongod.log-- from today 9:30

3.mloginfo

Mloginfo can include information about log files

Display query statistics for the log

Mloginfo mongod.log-queries

Sort the results

Mloginfo mongod.log-queries-sort countmloginfo mongod.log-queries-sort sum

Display restart information

Mloginfo mongod.log-restarts

Classified display log messages

Mloginfo mongod.log-distinct

Display connection information

Mloginfo mongod.log-connections

Display replication set information

Mloginfo mongod.log-rsstate

4.mplotqueries

Mplotqueries is a tool that can visualize operations in MongoDB log files.

-- group GROUP

The group parameter specifies what groups the data should be grouped according to, and then draws various charts with one color in each group. The default is scatter distribution map.

The possible values for GROUP are

Namespace

Filename

Operation

Thread

Log2code

Pattern

Mplotqueries mongod.log-group operation

Create a scatter distribution map

Mlogfilter mongod.log-- operation update-- namespace test.users | mplotqueries-- type histogram-- group "_ id: ObjectId\ ('([^'] +)'\)"

Mlogfilter first filters all update operations of test.users, and then draws a histogram based on _ id grouping

If the number of groups is too large, you can use-- group-limit to restrict the first few groups

Mplotqueries mongod.log-type range-group log2code-group-limit 10

-- type scatter (default)

Reference documentation:

Https://github.com/rueckstiess/mtools

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report