Databases 11 min read

Master MongoDB Monitoring with Mtools: Practical Commands & Visual Insights

Learn how to use the open‑source Mtools suite to inspect MongoDB logs, extract slow queries, generate performance charts, and overlay system metrics, enabling effective regular health checks, troubleshooting, and optimization for database administrators.

Efficient Ops
Efficient Ops
Efficient Ops
Master MongoDB Monitoring with Mtools: Practical Commands & Visual Insights

Monitoring and troubleshooting are critical for any database, and DBAs should perform regular inspections to understand health, performance, and potential issues.

This article explains how to use the Mtools toolkit to audit MongoDB databases and assist performance optimization.

1. Mtools Overview

Mtools is an open‑source toolkit created by MongoDB engineers to simplify log analysis and performance monitoring.

Mtools GitHub: https://github.com/rueckstiess/mtools

Mtools components include:

mlogfilter

mloginfo

mplotqueries

mlogvis

mlaunch

mgenerate

In this article we mainly use mlogfilter, mloginfo, and mplotqueries .

2. Basics

Brief introduction of the three tools.

mlogfilter can be understood as a log filter; its parameters are omitted for brevity.

mloginfo aggregates slow‑query information and provides statistics for common log patterns.

mplotqueries creates visual charts to help pinpoint problems.

3. Practical Commands (21 items)

1. List all slow logs in JSON format mlogfilter mongod.log-20150721 --slow --json 2. Import slow logs into a collection

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

3. Show slow logs for a specific namespace (over 100 ms)

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

4. List distinct values in the log mloginfo mongod.log-20150721 --distinct 5. Show connection sources mloginfo mongod.log-20150721 --connections 6. Display replica set state changes mloginfo mongod.log-20150721 --rsstate 7. Categorize slow queries

mloginfo --queries mongod.log-20150721

8. Plot slow‑query scatter diagram

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

9. Plot top 10 slow‑query points

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

10. Use logarithmic scale for better visibility

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

11. Plot slow‑query distribution for a single collection

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

12. Plot operation‑type distribution

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

13. Visualize collection scans

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

14. Customize Y‑axis (example: write lock "w")

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

15. Analyze connection churn in 30‑minute buckets

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

16. Histogram of updates by _id every 30 minutes

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

17. Hourly insert histogram

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

18. Plot intervals between slow logs (>10 min gaps)

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

19. Event timeline (example for getlasterror)

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

20. Visualize replica set state changes

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

21. Overlay multiple charts for quick troubleshooting

Add overlay with --overlay List overlays with --overlay list Reset overlays with

--overlay reset

4. Analysis Tips

Identify outliers in charts (e.g., points far above the norm) as potential problem areas.

Combine slow‑log data from mloginfo with MongoDB profiling to analyze query plans and optimize statements.

Overlay Mtools visualizations with system metrics (CPU, I/O, memory) for comprehensive troubleshooting.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performance optimizationMongoDBlog analysisDatabase MonitoringMtools
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.