mdbkit 0.5.4__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mdbkit-0.5.4 → mdbkit-0.6.0}/PKG-INFO +164 -37
- {mdbkit-0.5.4 → mdbkit-0.6.0}/README.md +162 -35
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/__init__.py +1 -1
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/advisor.py +4 -4
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/analysis.py +106 -18
- mdbkit-0.6.0/mdbkit/audit.py +266 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/cli.py +101 -20
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/demo.py +77 -7
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/explain.py +5 -5
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/filtering.py +3 -3
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/ftdc.py +35 -12
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/lab.py +182 -54
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/oslog.py +23 -9
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/parser.py +102 -16
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/render.py +114 -9
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/serverstatus.py +27 -25
- mdbkit-0.6.0/mdbkit/shelljson.py +248 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/triage.py +110 -10
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit.egg-info/PKG-INFO +164 -37
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit.egg-info/SOURCES.txt +5 -1
- {mdbkit-0.5.4 → mdbkit-0.6.0}/pyproject.toml +2 -2
- {mdbkit-0.5.4 → mdbkit-0.6.0}/tests/test_demo_lab.py +2 -1
- mdbkit-0.6.0/tests/test_render_e2e.py +237 -0
- mdbkit-0.6.0/tests/test_v060_hardening.py +706 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/LICENSE +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/compare.py +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/rebuild.py +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/report.py +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit/scripts.py +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit.egg-info/dependency_links.txt +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit.egg-info/entry_points.txt +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit.egg-info/requires.txt +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/mdbkit.egg-info/top_level.txt +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/setup.cfg +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/tests/test_explain.py +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/tests/test_ftdc.py +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/tests/test_mdbkit.py +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/tests/test_oslog_serverstatus.py +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/tests/test_rebuild_report.py +0 -0
- {mdbkit-0.5.4 → mdbkit-0.6.0}/tests/test_triage.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mdbkit
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Offline toolkit for MongoDB 4.4
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: Offline toolkit for MongoDB 4.4 to 9.0 structured logs: slow-query shapes, index advice, incident triage, startup configuration audit, FTDC decoding. A spiritual successor to mtools' log tools.
|
|
5
5
|
Author: Saqib Ameen Subhan
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/saqibameen86/mdbkit
|
|
@@ -33,8 +33,11 @@ Dynamic: license-file
|
|
|
33
33
|
[](LICENSE)
|
|
34
34
|
|
|
35
35
|
**An offline toolkit for MongoDB structured logs** — slow-query analysis,
|
|
36
|
-
deterministic index advice, incident triage,
|
|
37
|
-
For MongoDB 4.4
|
|
36
|
+
deterministic index advice, incident triage, a startup configuration audit,
|
|
37
|
+
and diagnostic-data decoding. For MongoDB 4.4 through 8.x and 9.0, from the
|
|
38
|
+
terminal, without connecting to anything.
|
|
39
|
+
**[Last checked against MongoDB 9.0.2, 8.3.13, 8.0.34 and 7.0.45](#compatibility)**
|
|
40
|
+
(October 2026).
|
|
38
41
|
|
|
39
42
|
A spiritual successor to mtools' log tools, which never learned to read the
|
|
40
43
|
JSON log format introduced in 4.4.
|
|
@@ -64,6 +67,7 @@ mdbkit demo --with-extras -o demo.log # a log + indexes.json, schema.json, e
|
|
|
64
67
|
mdbkit loginfo demo.log # what is in this log?
|
|
65
68
|
mdbkit queries demo.log # which query shapes cost the most?
|
|
66
69
|
mdbkit triage demo.log --window 0 # what went wrong, and when?
|
|
70
|
+
mdbkit audit demo.log # what did mongod warn about at startup?
|
|
67
71
|
mdbkit connections demo.log # who connected, and did anyone fail to?
|
|
68
72
|
mdbkit advise demo.log --indexes indexes.json --schema schema.json
|
|
69
73
|
mdbkit explain explain.json # read a saved explain plan
|
|
@@ -74,11 +78,13 @@ election, an index build, five failed logins from a service account, and an
|
|
|
74
78
|
aggregation burning 25 million document reads to return 261 documents — then
|
|
75
79
|
`advise` tells you which index fixes it.
|
|
76
80
|
|
|
77
|
-
Output is deterministic: the same `--seed`
|
|
78
|
-
|
|
81
|
+
Output is deterministic: the same `--seed` produces the same log, byte for
|
|
82
|
+
byte, on any machine and any Python version, so a demo behaves identically
|
|
83
|
+
every time. (Before 0.6.0 this held only within one Python process; across
|
|
84
|
+
runs some identifiers changed. Fixed.) Scenarios are `incident`, `healthy` (the
|
|
79
85
|
control case — useful for seeing what "nothing wrong" looks like) and `mixed`.
|
|
80
86
|
|
|
81
|
-
Ready for a real server? Jump to [the workflows](#the-
|
|
87
|
+
Ready for a real server? Jump to [the workflows](#the-questions-it-answers).
|
|
82
88
|
|
|
83
89
|
---
|
|
84
90
|
|
|
@@ -103,7 +109,7 @@ codebase specifically so that you can:
|
|
|
103
109
|
```bash
|
|
104
110
|
# 1. No network, no shell-outs, no eval anywhere in the analysis code
|
|
105
111
|
pip show -f mdbkit | head -3
|
|
106
|
-
grep -rn "socket\|urllib\|requests\|http\|eval(\|exec(" $(python -c "import mdbkit,os;print(os.path.dirname(mdbkit.__file__))")
|
|
112
|
+
grep -rn --include='*.py' "socket\|urllib\|requests\|http\|eval(\|exec(" $(python -c "import mdbkit,os;print(os.path.dirname(mdbkit.__file__))")
|
|
107
113
|
|
|
108
114
|
# 2. Confirm it has no dependencies
|
|
109
115
|
pip show mdbkit | grep Requires
|
|
@@ -112,9 +118,10 @@ pip show mdbkit | grep Requires
|
|
|
112
118
|
strace -f -e trace=network mdbkit queries mongod.log 2>&1 | grep -c socket
|
|
113
119
|
```
|
|
114
120
|
|
|
115
|
-
The grep
|
|
116
|
-
|
|
117
|
-
is
|
|
121
|
+
The grep matches exactly one file, `lab.py`: before it starts a *throwaway
|
|
122
|
+
test cluster* it tries to bind `127.0.0.1:<port>` to check the port is free.
|
|
123
|
+
That is also the only file that starts a process. Every analysis module comes
|
|
124
|
+
back clean. The lab is documented as an explicit exception below.
|
|
118
125
|
|
|
119
126
|
**What it does read:** the log file you point it at; optionally
|
|
120
127
|
`diagnostic.data` (metrics only, never documents); optionally `indexes.json`
|
|
@@ -257,7 +264,36 @@ updates — upgrades are always explicit.
|
|
|
257
264
|
|
|
258
265
|
---
|
|
259
266
|
|
|
260
|
-
##
|
|
267
|
+
## Compatibility
|
|
268
|
+
|
|
269
|
+
**Last checked against (October 2026):** MongoDB **9.0.2**, **8.3.13**,
|
|
270
|
+
**8.0.34** (LTS) and **7.0.45** (LTS). mdbkit reads the structured JSON log
|
|
271
|
+
format, so anything from **4.4** onwards works; 4.2 and earlier wrote plain
|
|
272
|
+
text logs and are not supported.
|
|
273
|
+
|
|
274
|
+
| MongoDB | What mdbkit uses from it |
|
|
275
|
+
|---|---|
|
|
276
|
+
| 4.4 – 7.0 | Everything except the 8.x-only fields below |
|
|
277
|
+
| 8.0 | `workingMillis` (time executing, as distinct from waiting), `queues.execution.totalTimeQueuedMicros` (ticket queue time), `queryShapeHash` (usable with `setQuerySettings`), `planCacheShapeHash`, the 8.0 transparent-huge-page guidance |
|
|
278
|
+
| 8.1+ | `<stage>Spills` / `<stage>SpilledBytes` (disk spills per stage) |
|
|
279
|
+
| 8.3+ | `peakTrackedMemBytes`, "Slow in-progress query" lines (id 1794200) |
|
|
280
|
+
| 9.0 | No changes to the fields mdbkit reads were found in the 9.0 release notes. Its `$queryStats` restructuring does not affect logs |
|
|
281
|
+
|
|
282
|
+
When a field is missing, because the log predates it, that part of the
|
|
283
|
+
output is left out. It is never guessed. FTDC decoding and `serverstatus`
|
|
284
|
+
read concurrency tickets from either the older
|
|
285
|
+
`wiredTiger.concurrentTransactions` or the newer `queues.execution` layout.
|
|
286
|
+
|
|
287
|
+
**How "checked" was established, honestly:** these versions were checked
|
|
288
|
+
against MongoDB's release notes and server source (log message ids, field
|
|
289
|
+
names, startup warnings), and every new field is covered by tests built from
|
|
290
|
+
those definitions. The 0.6.0 release was *not* additionally run against a
|
|
291
|
+
live 8.3 or 9.0 server. If you hit a line mdbkit misreads, please
|
|
292
|
+
[open an issue](../../issues) with the line (redact as you like).
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## The questions it answers
|
|
261
297
|
|
|
262
298
|
Every command reads files or stdin and accepts several files or a glob, so
|
|
263
299
|
rotated logs work as one stream: `mdbkit queries "mongod.log*"`.
|
|
@@ -272,7 +308,13 @@ mdbkit queries mongod.log --shape 1 # full detail on one shape
|
|
|
272
308
|
|
|
273
309
|
`cumMs` is time summed across **all** occurrences of a shape, not one query.
|
|
274
310
|
`scan` is documents examined per document returned — `1:1` is healthy,
|
|
275
|
-
`98889:1` is a missing index. `plan` shows what MongoDB actually chose
|
|
311
|
+
`98889:1` is a missing index. `plan` shows what MongoDB actually chose, with
|
|
312
|
+
`+SPILL` when the sort or group overflowed to disk.
|
|
313
|
+
|
|
314
|
+
On MongoDB 8.0+ mdbkit also separates **executing** from **waiting**. A
|
|
315
|
+
query that took 2 seconds but worked for 200 ms is not an index problem. It
|
|
316
|
+
was queued behind tickets, locks or flow control, and adding an index will
|
|
317
|
+
not help.
|
|
276
318
|
|
|
277
319
|
### 2. What index would fix it?
|
|
278
320
|
|
|
@@ -302,9 +344,11 @@ mdbkit triage mongod.log --report incident.html # something to attach to a ticke
|
|
|
302
344
|
```
|
|
303
345
|
|
|
304
346
|
Cluster health, elections, connection storms, hot collections, index builds,
|
|
305
|
-
error clusters, slow-query peaks
|
|
306
|
-
|
|
307
|
-
run.
|
|
347
|
+
error clusters, slow-query peaks, startup misconfiguration, time spent
|
|
348
|
+
waiting rather than working (8.0+), and still-running operations (8.3+) —
|
|
349
|
+
plus disk, memory, CPU and FTDC metrics when run on the database host. Every
|
|
350
|
+
finding ends with the next command to run. A shutdown followed by the server
|
|
351
|
+
listening again is reported as a restart (WARN), not an outage (CRIT).
|
|
308
352
|
|
|
309
353
|
### 4. Did my change actually help?
|
|
310
354
|
|
|
@@ -324,7 +368,28 @@ IMPROVED
|
|
|
324
368
|
The natural follow-up to `advise`: you created the index, a day passed, and
|
|
325
369
|
this tells you whether it worked.
|
|
326
370
|
|
|
327
|
-
### 5.
|
|
371
|
+
### 5. Is this server configured properly?
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
mdbkit audit /var/log/mongodb/mongod.log
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
```
|
|
378
|
+
[CRIT] Access control is not enabled
|
|
379
|
+
mongod said: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
|
|
380
|
+
fix: Anyone who can reach the port can read and write every database. Enable security.authorization ...
|
|
381
|
+
|
|
382
|
+
[WARN] Transparent huge pages should be re-enabled (8.0+ guidance)
|
|
383
|
+
mongod said: For customers running the current memory allocator, we suggest re-enabling transparent hugepages [...]
|
|
384
|
+
fix: MongoDB 8.0 recommends THP enabled for its new memory allocator, the opposite of the advice for 7.0 and earlier.
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
mongod checks its environment at every start and logs a warning for each
|
|
388
|
+
thing it does not like: no access control, low file limits, transparent huge
|
|
389
|
+
pages, NUMA, swappiness, running as root. They sit in the log right after
|
|
390
|
+
every restart, where almost nobody reads them. `triage` raises them too.
|
|
391
|
+
|
|
392
|
+
### 6. Why did it die? (and what does serverStatus say?)
|
|
328
393
|
|
|
329
394
|
```bash
|
|
330
395
|
mdbkit oslog /var/log/syslog # OOM kills, fd limits, I/O errors
|
|
@@ -502,7 +567,7 @@ query with different parameters is counted once.
|
|
|
502
567
|
| `mean` / `max` | Per-occurrence average and worst case |
|
|
503
568
|
| `docsEx` | Documents examined, summed across all occurrences |
|
|
504
569
|
| `scan` | Documents examined per document returned. `1:1` is ideal; `3444:1` means a missing or weak index |
|
|
505
|
-
| `plan` | The plan MongoDB chose: `COLLSCAN` (no index), `IXSCAN{fields}` (index used), `IDHACK` (`_id` lookup), `+SORT` (in-memory sort). `?` = the plan was not recorded on that line |
|
|
570
|
+
| `plan` | The plan MongoDB chose: `COLLSCAN` (no index), `IXSCAN{fields}` (index used), `IDHACK` (`_id` lookup), `+SORT` (in-memory sort), `+SPILL` (wrote temporary files to disk). `?` = the plan was not recorded on that line |
|
|
506
571
|
| `shape` | Fields and operators queried, with the sort |
|
|
507
572
|
|
|
508
573
|
```bash
|
|
@@ -513,31 +578,49 @@ mdbkit queries "mongod.log*" # rotated logs as one stream
|
|
|
513
578
|
mdbkit queries mongod.log --shape 1 # drill into the worst offender
|
|
514
579
|
```
|
|
515
580
|
|
|
516
|
-
`--shape N` expands one row of the table
|
|
581
|
+
`--shape N` expands one row of the table. On an 8.0+ log it also shows where
|
|
582
|
+
the time went and the identifiers MongoDB uses for this shape:
|
|
517
583
|
|
|
518
584
|
```
|
|
519
585
|
namespace : shop.events
|
|
586
|
+
operation : aggregate
|
|
520
587
|
shape : {tenantId:eq, ts:gte} sort:{ts:-1}
|
|
521
588
|
|
|
522
|
-
occurrences :
|
|
523
|
-
total time :
|
|
524
|
-
mean / max : 6.
|
|
525
|
-
docs examined :
|
|
526
|
-
docs returned :
|
|
589
|
+
occurrences : 53
|
|
590
|
+
total time : 5.7m
|
|
591
|
+
mean / max : 6.5s / 8.7s
|
|
592
|
+
docs examined : 47,170,000
|
|
593
|
+
docs returned : 477
|
|
527
594
|
scan ratio : 98889 examined per document returned
|
|
528
595
|
|
|
529
596
|
plans observed
|
|
530
|
-
COLLSCAN
|
|
597
|
+
COLLSCAN 53x
|
|
531
598
|
|
|
532
599
|
flags
|
|
533
600
|
COLLSCAN — no index used for at least one execution
|
|
534
601
|
in-memory SORT — results sorted after retrieval
|
|
535
602
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
603
|
+
where the time went (MongoDB 8.0+)
|
|
604
|
+
executing : 5.5m
|
|
605
|
+
waiting : 13.3s (4%) — tickets, locks, flow control
|
|
606
|
+
ticket queue : 12.0s of the wait
|
|
607
|
+
|
|
608
|
+
resources
|
|
609
|
+
disk spills : 159 (13.6 GiB written)
|
|
610
|
+
CPU time : 5.5m total
|
|
611
|
+
|
|
612
|
+
server identifiers
|
|
613
|
+
queryShapeHash : BDC6B796B132EBAF671210F40FC5155C05ED250F79996E68DC6C620CBD8972AE
|
|
614
|
+
pin or block this shape without a code change (8.0+):
|
|
615
|
+
db.adminCommand({setQuerySettings: "BDC6...72AE", settings: {...}})
|
|
616
|
+
planCacheShapeHash : 0F877C7D (queryHash before 8.0)
|
|
539
617
|
```
|
|
540
618
|
|
|
619
|
+
The `queryShapeHash` is the same value MongoDB shows in `explain`, the
|
|
620
|
+
profiler, `$currentOp` and `$queryStats`, so you can follow one shape
|
|
621
|
+
across all of them. mdbkit only prints the `setQuerySettings` command. It
|
|
622
|
+
never runs it.
|
|
623
|
+
|
|
541
624
|
---
|
|
542
625
|
|
|
543
626
|
### `mdbkit connections <log>`
|
|
@@ -732,6 +815,37 @@ mdbkit triage mongod.log --window 0 --no-sysprobe
|
|
|
732
815
|
|
|
733
816
|
---
|
|
734
817
|
|
|
818
|
+
### `mdbkit audit <log>`
|
|
819
|
+
|
|
820
|
+
Reads the warnings mongod logged when it started and explains each one:
|
|
821
|
+
access control, running as root, TLS certificate checks, file and
|
|
822
|
+
locked-memory limits, `vm.max_map_count`, transparent huge pages (with the
|
|
823
|
+
**8.0 reversal**: 7.0 and earlier want THP off, 8.0's new allocator wants it
|
|
824
|
+
on), glibc `rseq`, NUMA, overcommit, zone reclaim, swappiness, filesystem.
|
|
825
|
+
Warnings mdbkit does not recognise are still reported, in mongod's own words.
|
|
826
|
+
|
|
827
|
+
| Option | Description |
|
|
828
|
+
|---|---|
|
|
829
|
+
| `--exit-code` | Exit 2 on CRIT, 1 on WARN, else 0 |
|
|
830
|
+
| `--json` | Machine-readable output |
|
|
831
|
+
|
|
832
|
+
```bash
|
|
833
|
+
mdbkit audit /var/log/mongodb/mongod.log
|
|
834
|
+
mdbkit audit "/var/log/mongodb/mongod.log*" # include rotated logs
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
Startup warnings are written only when mongod starts. If the log covering
|
|
838
|
+
the last restart has rotated away, ask the running server instead. The
|
|
839
|
+
output of `getLog` works directly, in EJSON, mongosh's printed form, or a
|
|
840
|
+
UTF-16 file from Windows PowerShell:
|
|
841
|
+
|
|
842
|
+
```bash
|
|
843
|
+
mongosh --quiet --eval 'EJSON.stringify(db.adminCommand({getLog: "startupWarnings"}))' > startup.json
|
|
844
|
+
mdbkit audit startup.json
|
|
845
|
+
```
|
|
846
|
+
|
|
847
|
+
---
|
|
848
|
+
|
|
735
849
|
### `mdbkit ftdc {summary|timeline|export} <path>`
|
|
736
850
|
|
|
737
851
|
Decodes `diagnostic.data` — **FTDC (Full-Time Diagnostic Data Capture)**, the
|
|
@@ -955,6 +1069,13 @@ log immediately contains something worth analysing.
|
|
|
955
1069
|
|
|
956
1070
|
**Safety.** The lab binds to `127.0.0.1` only, refuses to use or delete any
|
|
957
1071
|
directory it did not create, and never touches a MongoDB it did not start.
|
|
1072
|
+
Before it signals a process it checks that the pid still belongs to one of
|
|
1073
|
+
its own `mongod`s (its command line names the lab's data directory), so a
|
|
1074
|
+
stale pid file can never kill something unrelated. `destroy` refuses to
|
|
1075
|
+
delete data while a lab node is still running. If a port is already taken it
|
|
1076
|
+
says so before starting anything. If a start fails halfway, the lab is left
|
|
1077
|
+
in a state `mdbkit lab destroy --yes` can clean up, and the error says so.
|
|
1078
|
+
Logs are appended across restarts rather than overwritten.
|
|
958
1079
|
It is a laptop and scratch-VM tool, not a deployment tool.
|
|
959
1080
|
|
|
960
1081
|
---
|
|
@@ -1022,8 +1143,14 @@ looks like slowness with no slow query to blame), **WiredTiger cache** against
|
|
|
1022
1143
|
the 80% background-eviction and 95% application-thread-eviction thresholds,
|
|
1023
1144
|
**dirty cache**, **application-thread eviction**, **connection headroom**,
|
|
1024
1145
|
**queued readers and writers**, **assertions**, **flow control**, replication
|
|
1025
|
-
role and process memory.
|
|
1026
|
-
`wiredTiger.concurrentTransactions`
|
|
1146
|
+
role and process memory. Tickets are read from either the older
|
|
1147
|
+
`wiredTiger.concurrentTransactions` layout or the newer `queues.execution`.
|
|
1148
|
+
|
|
1149
|
+
**Paste-friendly.** The file can be strict JSON, EJSON, or exactly what
|
|
1150
|
+
mongosh prints when you run `db.serverStatus()` and copy the output:
|
|
1151
|
+
unquoted keys, `Long('42')`, `ISODate(...)`, `Timestamp({...})`. A file
|
|
1152
|
+
redirected in Windows PowerShell (UTF-16) works too. Nothing in the file is
|
|
1153
|
+
ever evaluated; it is tokenised as data.
|
|
1027
1154
|
|
|
1028
1155
|
**Two dumps give true rates.** Almost everything in serverStatus is cumulative
|
|
1029
1156
|
since process start, so a single dump only yields lifetime averages:
|
|
@@ -1100,9 +1227,13 @@ mdbkit export-script schema > export_schema.js
|
|
|
1100
1227
|
Terminal output is and will remain first-class — this tool is built for the
|
|
1101
1228
|
Linux box the database actually runs on.
|
|
1102
1229
|
|
|
1103
|
-
**Shipped in v0.
|
|
1104
|
-
|
|
1105
|
-
|
|
1230
|
+
**Shipped in v0.6:** MongoDB 8.x/9.0 support (executing vs waiting time,
|
|
1231
|
+
query shape hashes, disk spills, peak memory, in-progress operations, the
|
|
1232
|
+
8.0 ticket layout in FTDC), the `audit` command, mongosh-paste input, and a
|
|
1233
|
+
hardening pass. Before that: v0.5's `oslog` and `serverstatus`, v0.4's
|
|
1234
|
+
`compare`, rotated-log globbing and per-shape drill-down, v0.3's `demo` and
|
|
1235
|
+
`lab`, and v0.2's FTDC decoding, incident triage, query reconstruction and
|
|
1236
|
+
shareable reports.
|
|
1106
1237
|
|
|
1107
1238
|
Next up, roughly in order:
|
|
1108
1239
|
|
|
@@ -1110,10 +1241,6 @@ Next up, roughly in order:
|
|
|
1110
1241
|
sharded failure — a query with no shard key fanning out to every shard — is
|
|
1111
1242
|
visible in the log. Also chunk migrations, balancer windows and jumbo
|
|
1112
1243
|
chunks. Would come with `mdbkit lab --sharded` so it can be tested.
|
|
1113
|
-
* **Startup configuration audit.** mongod logs warnings at startup about
|
|
1114
|
-
transparent huge pages, readahead, ulimits, NUMA and filesystem choice.
|
|
1115
|
-
These are classic production misconfigurations and they are already in
|
|
1116
|
-
your log — nothing new needs collecting.
|
|
1117
1244
|
* **Index usage candidates.** Prefix-redundant indexes (an index on `{a: 1}`
|
|
1118
1245
|
when `{a: 1, b: 1}` exists) are worth *examining*, but static analysis is
|
|
1119
1246
|
not sufficient grounds to drop one — the planner may still be choosing it.
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
8
|
**An offline toolkit for MongoDB structured logs** — slow-query analysis,
|
|
9
|
-
deterministic index advice, incident triage,
|
|
10
|
-
For MongoDB 4.4
|
|
9
|
+
deterministic index advice, incident triage, a startup configuration audit,
|
|
10
|
+
and diagnostic-data decoding. For MongoDB 4.4 through 8.x and 9.0, from the
|
|
11
|
+
terminal, without connecting to anything.
|
|
12
|
+
**[Last checked against MongoDB 9.0.2, 8.3.13, 8.0.34 and 7.0.45](#compatibility)**
|
|
13
|
+
(October 2026).
|
|
11
14
|
|
|
12
15
|
A spiritual successor to mtools' log tools, which never learned to read the
|
|
13
16
|
JSON log format introduced in 4.4.
|
|
@@ -37,6 +40,7 @@ mdbkit demo --with-extras -o demo.log # a log + indexes.json, schema.json, e
|
|
|
37
40
|
mdbkit loginfo demo.log # what is in this log?
|
|
38
41
|
mdbkit queries demo.log # which query shapes cost the most?
|
|
39
42
|
mdbkit triage demo.log --window 0 # what went wrong, and when?
|
|
43
|
+
mdbkit audit demo.log # what did mongod warn about at startup?
|
|
40
44
|
mdbkit connections demo.log # who connected, and did anyone fail to?
|
|
41
45
|
mdbkit advise demo.log --indexes indexes.json --schema schema.json
|
|
42
46
|
mdbkit explain explain.json # read a saved explain plan
|
|
@@ -47,11 +51,13 @@ election, an index build, five failed logins from a service account, and an
|
|
|
47
51
|
aggregation burning 25 million document reads to return 261 documents — then
|
|
48
52
|
`advise` tells you which index fixes it.
|
|
49
53
|
|
|
50
|
-
Output is deterministic: the same `--seed`
|
|
51
|
-
|
|
54
|
+
Output is deterministic: the same `--seed` produces the same log, byte for
|
|
55
|
+
byte, on any machine and any Python version, so a demo behaves identically
|
|
56
|
+
every time. (Before 0.6.0 this held only within one Python process; across
|
|
57
|
+
runs some identifiers changed. Fixed.) Scenarios are `incident`, `healthy` (the
|
|
52
58
|
control case — useful for seeing what "nothing wrong" looks like) and `mixed`.
|
|
53
59
|
|
|
54
|
-
Ready for a real server? Jump to [the workflows](#the-
|
|
60
|
+
Ready for a real server? Jump to [the workflows](#the-questions-it-answers).
|
|
55
61
|
|
|
56
62
|
---
|
|
57
63
|
|
|
@@ -76,7 +82,7 @@ codebase specifically so that you can:
|
|
|
76
82
|
```bash
|
|
77
83
|
# 1. No network, no shell-outs, no eval anywhere in the analysis code
|
|
78
84
|
pip show -f mdbkit | head -3
|
|
79
|
-
grep -rn "socket\|urllib\|requests\|http\|eval(\|exec(" $(python -c "import mdbkit,os;print(os.path.dirname(mdbkit.__file__))")
|
|
85
|
+
grep -rn --include='*.py' "socket\|urllib\|requests\|http\|eval(\|exec(" $(python -c "import mdbkit,os;print(os.path.dirname(mdbkit.__file__))")
|
|
80
86
|
|
|
81
87
|
# 2. Confirm it has no dependencies
|
|
82
88
|
pip show mdbkit | grep Requires
|
|
@@ -85,9 +91,10 @@ pip show mdbkit | grep Requires
|
|
|
85
91
|
strace -f -e trace=network mdbkit queries mongod.log 2>&1 | grep -c socket
|
|
86
92
|
```
|
|
87
93
|
|
|
88
|
-
The grep
|
|
89
|
-
|
|
90
|
-
is
|
|
94
|
+
The grep matches exactly one file, `lab.py`: before it starts a *throwaway
|
|
95
|
+
test cluster* it tries to bind `127.0.0.1:<port>` to check the port is free.
|
|
96
|
+
That is also the only file that starts a process. Every analysis module comes
|
|
97
|
+
back clean. The lab is documented as an explicit exception below.
|
|
91
98
|
|
|
92
99
|
**What it does read:** the log file you point it at; optionally
|
|
93
100
|
`diagnostic.data` (metrics only, never documents); optionally `indexes.json`
|
|
@@ -230,7 +237,36 @@ updates — upgrades are always explicit.
|
|
|
230
237
|
|
|
231
238
|
---
|
|
232
239
|
|
|
233
|
-
##
|
|
240
|
+
## Compatibility
|
|
241
|
+
|
|
242
|
+
**Last checked against (October 2026):** MongoDB **9.0.2**, **8.3.13**,
|
|
243
|
+
**8.0.34** (LTS) and **7.0.45** (LTS). mdbkit reads the structured JSON log
|
|
244
|
+
format, so anything from **4.4** onwards works; 4.2 and earlier wrote plain
|
|
245
|
+
text logs and are not supported.
|
|
246
|
+
|
|
247
|
+
| MongoDB | What mdbkit uses from it |
|
|
248
|
+
|---|---|
|
|
249
|
+
| 4.4 – 7.0 | Everything except the 8.x-only fields below |
|
|
250
|
+
| 8.0 | `workingMillis` (time executing, as distinct from waiting), `queues.execution.totalTimeQueuedMicros` (ticket queue time), `queryShapeHash` (usable with `setQuerySettings`), `planCacheShapeHash`, the 8.0 transparent-huge-page guidance |
|
|
251
|
+
| 8.1+ | `<stage>Spills` / `<stage>SpilledBytes` (disk spills per stage) |
|
|
252
|
+
| 8.3+ | `peakTrackedMemBytes`, "Slow in-progress query" lines (id 1794200) |
|
|
253
|
+
| 9.0 | No changes to the fields mdbkit reads were found in the 9.0 release notes. Its `$queryStats` restructuring does not affect logs |
|
|
254
|
+
|
|
255
|
+
When a field is missing, because the log predates it, that part of the
|
|
256
|
+
output is left out. It is never guessed. FTDC decoding and `serverstatus`
|
|
257
|
+
read concurrency tickets from either the older
|
|
258
|
+
`wiredTiger.concurrentTransactions` or the newer `queues.execution` layout.
|
|
259
|
+
|
|
260
|
+
**How "checked" was established, honestly:** these versions were checked
|
|
261
|
+
against MongoDB's release notes and server source (log message ids, field
|
|
262
|
+
names, startup warnings), and every new field is covered by tests built from
|
|
263
|
+
those definitions. The 0.6.0 release was *not* additionally run against a
|
|
264
|
+
live 8.3 or 9.0 server. If you hit a line mdbkit misreads, please
|
|
265
|
+
[open an issue](../../issues) with the line (redact as you like).
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## The questions it answers
|
|
234
270
|
|
|
235
271
|
Every command reads files or stdin and accepts several files or a glob, so
|
|
236
272
|
rotated logs work as one stream: `mdbkit queries "mongod.log*"`.
|
|
@@ -245,7 +281,13 @@ mdbkit queries mongod.log --shape 1 # full detail on one shape
|
|
|
245
281
|
|
|
246
282
|
`cumMs` is time summed across **all** occurrences of a shape, not one query.
|
|
247
283
|
`scan` is documents examined per document returned — `1:1` is healthy,
|
|
248
|
-
`98889:1` is a missing index. `plan` shows what MongoDB actually chose
|
|
284
|
+
`98889:1` is a missing index. `plan` shows what MongoDB actually chose, with
|
|
285
|
+
`+SPILL` when the sort or group overflowed to disk.
|
|
286
|
+
|
|
287
|
+
On MongoDB 8.0+ mdbkit also separates **executing** from **waiting**. A
|
|
288
|
+
query that took 2 seconds but worked for 200 ms is not an index problem. It
|
|
289
|
+
was queued behind tickets, locks or flow control, and adding an index will
|
|
290
|
+
not help.
|
|
249
291
|
|
|
250
292
|
### 2. What index would fix it?
|
|
251
293
|
|
|
@@ -275,9 +317,11 @@ mdbkit triage mongod.log --report incident.html # something to attach to a ticke
|
|
|
275
317
|
```
|
|
276
318
|
|
|
277
319
|
Cluster health, elections, connection storms, hot collections, index builds,
|
|
278
|
-
error clusters, slow-query peaks
|
|
279
|
-
|
|
280
|
-
run.
|
|
320
|
+
error clusters, slow-query peaks, startup misconfiguration, time spent
|
|
321
|
+
waiting rather than working (8.0+), and still-running operations (8.3+) —
|
|
322
|
+
plus disk, memory, CPU and FTDC metrics when run on the database host. Every
|
|
323
|
+
finding ends with the next command to run. A shutdown followed by the server
|
|
324
|
+
listening again is reported as a restart (WARN), not an outage (CRIT).
|
|
281
325
|
|
|
282
326
|
### 4. Did my change actually help?
|
|
283
327
|
|
|
@@ -297,7 +341,28 @@ IMPROVED
|
|
|
297
341
|
The natural follow-up to `advise`: you created the index, a day passed, and
|
|
298
342
|
this tells you whether it worked.
|
|
299
343
|
|
|
300
|
-
### 5.
|
|
344
|
+
### 5. Is this server configured properly?
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
mdbkit audit /var/log/mongodb/mongod.log
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
[CRIT] Access control is not enabled
|
|
352
|
+
mongod said: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
|
|
353
|
+
fix: Anyone who can reach the port can read and write every database. Enable security.authorization ...
|
|
354
|
+
|
|
355
|
+
[WARN] Transparent huge pages should be re-enabled (8.0+ guidance)
|
|
356
|
+
mongod said: For customers running the current memory allocator, we suggest re-enabling transparent hugepages [...]
|
|
357
|
+
fix: MongoDB 8.0 recommends THP enabled for its new memory allocator, the opposite of the advice for 7.0 and earlier.
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
mongod checks its environment at every start and logs a warning for each
|
|
361
|
+
thing it does not like: no access control, low file limits, transparent huge
|
|
362
|
+
pages, NUMA, swappiness, running as root. They sit in the log right after
|
|
363
|
+
every restart, where almost nobody reads them. `triage` raises them too.
|
|
364
|
+
|
|
365
|
+
### 6. Why did it die? (and what does serverStatus say?)
|
|
301
366
|
|
|
302
367
|
```bash
|
|
303
368
|
mdbkit oslog /var/log/syslog # OOM kills, fd limits, I/O errors
|
|
@@ -475,7 +540,7 @@ query with different parameters is counted once.
|
|
|
475
540
|
| `mean` / `max` | Per-occurrence average and worst case |
|
|
476
541
|
| `docsEx` | Documents examined, summed across all occurrences |
|
|
477
542
|
| `scan` | Documents examined per document returned. `1:1` is ideal; `3444:1` means a missing or weak index |
|
|
478
|
-
| `plan` | The plan MongoDB chose: `COLLSCAN` (no index), `IXSCAN{fields}` (index used), `IDHACK` (`_id` lookup), `+SORT` (in-memory sort). `?` = the plan was not recorded on that line |
|
|
543
|
+
| `plan` | The plan MongoDB chose: `COLLSCAN` (no index), `IXSCAN{fields}` (index used), `IDHACK` (`_id` lookup), `+SORT` (in-memory sort), `+SPILL` (wrote temporary files to disk). `?` = the plan was not recorded on that line |
|
|
479
544
|
| `shape` | Fields and operators queried, with the sort |
|
|
480
545
|
|
|
481
546
|
```bash
|
|
@@ -486,31 +551,49 @@ mdbkit queries "mongod.log*" # rotated logs as one stream
|
|
|
486
551
|
mdbkit queries mongod.log --shape 1 # drill into the worst offender
|
|
487
552
|
```
|
|
488
553
|
|
|
489
|
-
`--shape N` expands one row of the table
|
|
554
|
+
`--shape N` expands one row of the table. On an 8.0+ log it also shows where
|
|
555
|
+
the time went and the identifiers MongoDB uses for this shape:
|
|
490
556
|
|
|
491
557
|
```
|
|
492
558
|
namespace : shop.events
|
|
559
|
+
operation : aggregate
|
|
493
560
|
shape : {tenantId:eq, ts:gte} sort:{ts:-1}
|
|
494
561
|
|
|
495
|
-
occurrences :
|
|
496
|
-
total time :
|
|
497
|
-
mean / max : 6.
|
|
498
|
-
docs examined :
|
|
499
|
-
docs returned :
|
|
562
|
+
occurrences : 53
|
|
563
|
+
total time : 5.7m
|
|
564
|
+
mean / max : 6.5s / 8.7s
|
|
565
|
+
docs examined : 47,170,000
|
|
566
|
+
docs returned : 477
|
|
500
567
|
scan ratio : 98889 examined per document returned
|
|
501
568
|
|
|
502
569
|
plans observed
|
|
503
|
-
COLLSCAN
|
|
570
|
+
COLLSCAN 53x
|
|
504
571
|
|
|
505
572
|
flags
|
|
506
573
|
COLLSCAN — no index used for at least one execution
|
|
507
574
|
in-memory SORT — results sorted after retrieval
|
|
508
575
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
576
|
+
where the time went (MongoDB 8.0+)
|
|
577
|
+
executing : 5.5m
|
|
578
|
+
waiting : 13.3s (4%) — tickets, locks, flow control
|
|
579
|
+
ticket queue : 12.0s of the wait
|
|
580
|
+
|
|
581
|
+
resources
|
|
582
|
+
disk spills : 159 (13.6 GiB written)
|
|
583
|
+
CPU time : 5.5m total
|
|
584
|
+
|
|
585
|
+
server identifiers
|
|
586
|
+
queryShapeHash : BDC6B796B132EBAF671210F40FC5155C05ED250F79996E68DC6C620CBD8972AE
|
|
587
|
+
pin or block this shape without a code change (8.0+):
|
|
588
|
+
db.adminCommand({setQuerySettings: "BDC6...72AE", settings: {...}})
|
|
589
|
+
planCacheShapeHash : 0F877C7D (queryHash before 8.0)
|
|
512
590
|
```
|
|
513
591
|
|
|
592
|
+
The `queryShapeHash` is the same value MongoDB shows in `explain`, the
|
|
593
|
+
profiler, `$currentOp` and `$queryStats`, so you can follow one shape
|
|
594
|
+
across all of them. mdbkit only prints the `setQuerySettings` command. It
|
|
595
|
+
never runs it.
|
|
596
|
+
|
|
514
597
|
---
|
|
515
598
|
|
|
516
599
|
### `mdbkit connections <log>`
|
|
@@ -705,6 +788,37 @@ mdbkit triage mongod.log --window 0 --no-sysprobe
|
|
|
705
788
|
|
|
706
789
|
---
|
|
707
790
|
|
|
791
|
+
### `mdbkit audit <log>`
|
|
792
|
+
|
|
793
|
+
Reads the warnings mongod logged when it started and explains each one:
|
|
794
|
+
access control, running as root, TLS certificate checks, file and
|
|
795
|
+
locked-memory limits, `vm.max_map_count`, transparent huge pages (with the
|
|
796
|
+
**8.0 reversal**: 7.0 and earlier want THP off, 8.0's new allocator wants it
|
|
797
|
+
on), glibc `rseq`, NUMA, overcommit, zone reclaim, swappiness, filesystem.
|
|
798
|
+
Warnings mdbkit does not recognise are still reported, in mongod's own words.
|
|
799
|
+
|
|
800
|
+
| Option | Description |
|
|
801
|
+
|---|---|
|
|
802
|
+
| `--exit-code` | Exit 2 on CRIT, 1 on WARN, else 0 |
|
|
803
|
+
| `--json` | Machine-readable output |
|
|
804
|
+
|
|
805
|
+
```bash
|
|
806
|
+
mdbkit audit /var/log/mongodb/mongod.log
|
|
807
|
+
mdbkit audit "/var/log/mongodb/mongod.log*" # include rotated logs
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
Startup warnings are written only when mongod starts. If the log covering
|
|
811
|
+
the last restart has rotated away, ask the running server instead. The
|
|
812
|
+
output of `getLog` works directly, in EJSON, mongosh's printed form, or a
|
|
813
|
+
UTF-16 file from Windows PowerShell:
|
|
814
|
+
|
|
815
|
+
```bash
|
|
816
|
+
mongosh --quiet --eval 'EJSON.stringify(db.adminCommand({getLog: "startupWarnings"}))' > startup.json
|
|
817
|
+
mdbkit audit startup.json
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
---
|
|
821
|
+
|
|
708
822
|
### `mdbkit ftdc {summary|timeline|export} <path>`
|
|
709
823
|
|
|
710
824
|
Decodes `diagnostic.data` — **FTDC (Full-Time Diagnostic Data Capture)**, the
|
|
@@ -928,6 +1042,13 @@ log immediately contains something worth analysing.
|
|
|
928
1042
|
|
|
929
1043
|
**Safety.** The lab binds to `127.0.0.1` only, refuses to use or delete any
|
|
930
1044
|
directory it did not create, and never touches a MongoDB it did not start.
|
|
1045
|
+
Before it signals a process it checks that the pid still belongs to one of
|
|
1046
|
+
its own `mongod`s (its command line names the lab's data directory), so a
|
|
1047
|
+
stale pid file can never kill something unrelated. `destroy` refuses to
|
|
1048
|
+
delete data while a lab node is still running. If a port is already taken it
|
|
1049
|
+
says so before starting anything. If a start fails halfway, the lab is left
|
|
1050
|
+
in a state `mdbkit lab destroy --yes` can clean up, and the error says so.
|
|
1051
|
+
Logs are appended across restarts rather than overwritten.
|
|
931
1052
|
It is a laptop and scratch-VM tool, not a deployment tool.
|
|
932
1053
|
|
|
933
1054
|
---
|
|
@@ -995,8 +1116,14 @@ looks like slowness with no slow query to blame), **WiredTiger cache** against
|
|
|
995
1116
|
the 80% background-eviction and 95% application-thread-eviction thresholds,
|
|
996
1117
|
**dirty cache**, **application-thread eviction**, **connection headroom**,
|
|
997
1118
|
**queued readers and writers**, **assertions**, **flow control**, replication
|
|
998
|
-
role and process memory.
|
|
999
|
-
`wiredTiger.concurrentTransactions`
|
|
1119
|
+
role and process memory. Tickets are read from either the older
|
|
1120
|
+
`wiredTiger.concurrentTransactions` layout or the newer `queues.execution`.
|
|
1121
|
+
|
|
1122
|
+
**Paste-friendly.** The file can be strict JSON, EJSON, or exactly what
|
|
1123
|
+
mongosh prints when you run `db.serverStatus()` and copy the output:
|
|
1124
|
+
unquoted keys, `Long('42')`, `ISODate(...)`, `Timestamp({...})`. A file
|
|
1125
|
+
redirected in Windows PowerShell (UTF-16) works too. Nothing in the file is
|
|
1126
|
+
ever evaluated; it is tokenised as data.
|
|
1000
1127
|
|
|
1001
1128
|
**Two dumps give true rates.** Almost everything in serverStatus is cumulative
|
|
1002
1129
|
since process start, so a single dump only yields lifetime averages:
|
|
@@ -1073,9 +1200,13 @@ mdbkit export-script schema > export_schema.js
|
|
|
1073
1200
|
Terminal output is and will remain first-class — this tool is built for the
|
|
1074
1201
|
Linux box the database actually runs on.
|
|
1075
1202
|
|
|
1076
|
-
**Shipped in v0.
|
|
1077
|
-
|
|
1078
|
-
|
|
1203
|
+
**Shipped in v0.6:** MongoDB 8.x/9.0 support (executing vs waiting time,
|
|
1204
|
+
query shape hashes, disk spills, peak memory, in-progress operations, the
|
|
1205
|
+
8.0 ticket layout in FTDC), the `audit` command, mongosh-paste input, and a
|
|
1206
|
+
hardening pass. Before that: v0.5's `oslog` and `serverstatus`, v0.4's
|
|
1207
|
+
`compare`, rotated-log globbing and per-shape drill-down, v0.3's `demo` and
|
|
1208
|
+
`lab`, and v0.2's FTDC decoding, incident triage, query reconstruction and
|
|
1209
|
+
shareable reports.
|
|
1079
1210
|
|
|
1080
1211
|
Next up, roughly in order:
|
|
1081
1212
|
|
|
@@ -1083,10 +1214,6 @@ Next up, roughly in order:
|
|
|
1083
1214
|
sharded failure — a query with no shard key fanning out to every shard — is
|
|
1084
1215
|
visible in the log. Also chunk migrations, balancer windows and jumbo
|
|
1085
1216
|
chunks. Would come with `mdbkit lab --sharded` so it can be tested.
|
|
1086
|
-
* **Startup configuration audit.** mongod logs warnings at startup about
|
|
1087
|
-
transparent huge pages, readahead, ulimits, NUMA and filesystem choice.
|
|
1088
|
-
These are classic production misconfigurations and they are already in
|
|
1089
|
-
your log — nothing new needs collecting.
|
|
1090
1217
|
* **Index usage candidates.** Prefix-redundant indexes (an index on `{a: 1}`
|
|
1091
1218
|
when `{a: 1, b: 1}` exists) are worth *examining*, but static analysis is
|
|
1092
1219
|
not sufficient grounds to drop one — the planner may still be choosing it.
|