mdbkit 0.7.0__tar.gz → 0.8.1__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.7.0/mdbkit.egg-info → mdbkit-0.8.1}/PKG-INFO +369 -129
- mdbkit-0.7.0/PKG-INFO → mdbkit-0.8.1/README.md +356 -152
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/__init__.py +1 -1
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/analysis.py +101 -1
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/cli.py +191 -50
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/filtering.py +31 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/ftdc.py +122 -11
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/host.py +49 -14
- mdbkit-0.8.1/mdbkit/indexusage.py +319 -0
- mdbkit-0.8.1/mdbkit/lab.py +883 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/rebuild.py +26 -1
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/render.py +134 -20
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/scripts.py +28 -5
- mdbkit-0.8.1/mdbkit/sharding.py +415 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/triage.py +427 -95
- mdbkit-0.7.0/README.md → mdbkit-0.8.1/mdbkit.egg-info/PKG-INFO +392 -125
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit.egg-info/SOURCES.txt +8 -1
- {mdbkit-0.7.0 → mdbkit-0.8.1}/pyproject.toml +17 -4
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_ftdc.py +1 -1
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_host.py +1 -1
- mdbkit-0.8.1/tests/test_indexes.py +185 -0
- mdbkit-0.8.1/tests/test_query_hash.py +144 -0
- mdbkit-0.8.1/tests/test_real_failures.py +181 -0
- mdbkit-0.8.1/tests/test_sharded.py +187 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_triage.py +2 -2
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_v060_hardening.py +82 -0
- mdbkit-0.8.1/tests/test_v080.py +151 -0
- mdbkit-0.7.0/mdbkit/lab.py +0 -542
- {mdbkit-0.7.0 → mdbkit-0.8.1}/LICENSE +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/advisor.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/audit.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/compare.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/demo.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/explain.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/oslog.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/parser.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/report.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/serverstatus.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit/shelljson.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit.egg-info/dependency_links.txt +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit.egg-info/entry_points.txt +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit.egg-info/requires.txt +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/mdbkit.egg-info/top_level.txt +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/setup.cfg +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_demo_lab.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_explain.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_mdbkit.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_oslog_serverstatus.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_real_servers.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_rebuild_report.py +0 -0
- {mdbkit-0.7.0 → mdbkit-0.8.1}/tests/test_render_e2e.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 to 9.0
|
|
3
|
+
Version: 0.8.1
|
|
4
|
+
Summary: Offline toolkit for MongoDB 4.4 to 9.0 logs and diagnostics: slow-query shapes, index advice and index usage, incident triage, sharded clusters, multi-instance hosts, 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
|
|
@@ -9,13 +9,22 @@ Project-URL: Repository, https://github.com/saqibameen86/mdbkit
|
|
|
9
9
|
Project-URL: Documentation, https://github.com/saqibameen86/mdbkit#readme
|
|
10
10
|
Project-URL: Issues, https://github.com/saqibameen86/mdbkit/issues
|
|
11
11
|
Project-URL: Changelog, https://github.com/saqibameen86/mdbkit/releases
|
|
12
|
-
Keywords: mongodb,mongodb-logs,logv2,mtools,mloginfo,mongod,slow-query,slow-query-log,log-analysis,log-parser,index-advisor,dba,sre,devops,ftdc,diagnostic-data,explain-plan,query-performance,database-performance,replica-set,wiredtiger,troubleshooting,incident-response
|
|
13
|
-
Classifier: Development Status ::
|
|
12
|
+
Keywords: mongodb,mongodb-logs,logv2,mtools,mloginfo,mongod,slow-query,slow-query-log,log-analysis,log-parser,index-advisor,dba,sre,devops,ftdc,diagnostic-data,explain-plan,query-performance,database-performance,replica-set,wiredtiger,troubleshooting,incident-response,sharding,mongos,sharded-cluster,chunk-migration,index-usage
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
14
|
Classifier: Environment :: Console
|
|
15
15
|
Classifier: Intended Audience :: System Administrators
|
|
16
16
|
Classifier: Intended Audience :: Developers
|
|
17
17
|
Classifier: License :: OSI Approved :: MIT License
|
|
18
18
|
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
27
|
+
Classifier: Operating System :: OS Independent
|
|
19
28
|
Classifier: Topic :: Database
|
|
20
29
|
Classifier: Topic :: System :: Systems Administration
|
|
21
30
|
Requires-Python: >=3.8
|
|
@@ -32,12 +41,14 @@ Dynamic: license-file
|
|
|
32
41
|
[](https://pypi.org/project/mdbkit/)
|
|
33
42
|
[](LICENSE)
|
|
34
43
|
|
|
35
|
-
**An offline toolkit for MongoDB
|
|
36
|
-
deterministic index advice,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(
|
|
44
|
+
**An offline toolkit for MongoDB logs and diagnostics** — slow-query
|
|
45
|
+
analysis, deterministic index advice, unused and redundant indexes, incident
|
|
46
|
+
triage, sharded clusters, hosts running many mongods, a startup
|
|
47
|
+
configuration audit, and diagnostic-data (FTDC) decoding. For MongoDB 4.4
|
|
48
|
+
through 9.0, from the terminal, without connecting to anything.
|
|
49
|
+
**[Tested against real MongoDB 9.0.2, 8.3.11, 8.0.32, 7.0.43 and 6.0.29](#compatibility)**
|
|
50
|
+
— replica sets, standalones and sharded clusters (October 2026) — and
|
|
51
|
+
re-checked on 9.0.8, 8.3.17, 8.0.38 and 7.0.48 (December 2026).
|
|
41
52
|
|
|
42
53
|
A spiritual successor to mtools' log tools, which never learned to read the
|
|
43
54
|
JSON log format introduced in 4.4.
|
|
@@ -267,40 +278,55 @@ updates — upgrades are always explicit.
|
|
|
267
278
|
## Compatibility
|
|
268
279
|
|
|
269
280
|
**Tested against (October 2026):** MongoDB **9.0.2**, **8.3.11**, **8.0.32**
|
|
270
|
-
(LTS)
|
|
271
|
-
|
|
272
|
-
|
|
281
|
+
(LTS), **7.0.43** (LTS) and **6.0.29**, the newest release in each series at
|
|
282
|
+
the time: replica sets and standalones on all five, and sharded clusters
|
|
283
|
+
(mongos, shards and config servers) on 6.0, 7.0, 8.0 and 9.0.
|
|
284
|
+
|
|
285
|
+
**Re-checked (December 2026)** on the newest patches, **9.0.8**, **8.3.17**,
|
|
286
|
+
**8.0.38** and **7.0.48**: each was run as a replica set (seeded, its primary
|
|
287
|
+
killed and restarted, stepped down) and every command was run on the result;
|
|
288
|
+
9.0.8 and 8.0.38 also as a sharded cluster. None of these patches changed a
|
|
289
|
+
log field, message or metric that mdbkit reads.
|
|
290
|
+
|
|
291
|
+
mdbkit reads the structured JSON log format, so anything
|
|
292
|
+
from **4.4** onwards works; 4.2 and earlier wrote plain text logs and are not
|
|
293
|
+
supported.
|
|
273
294
|
|
|
274
295
|
| MongoDB | What mdbkit uses from it |
|
|
275
296
|
|---|---|
|
|
276
297
|
| 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 |
|
|
298
|
+
| 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, and FTDC's new layout (sharded processes group metrics by role; WiredTiger checkpoint and eviction statistics were renamed) |
|
|
278
299
|
| 8.1+ | `<stage>Spills` / `<stage>SpilledBytes` (disk spills per stage) |
|
|
279
300
|
| 8.3+ | "Slow in-progress query" lines (id 1794200, component `SLOWPROG`), logged by default for operations still running after 5 s (`--defaultSlowInProgMS`), and `peakTrackedMemBytes` |
|
|
280
301
|
| 9.0 | Same log fields as 8.3. Adds a few fields mdbkit does not use yet (`delinquencyInfo`, `queues.ingress`) |
|
|
281
302
|
|
|
282
303
|
When a field is missing because the log predates it, that part of the output
|
|
283
|
-
is left out. It is never guessed.
|
|
284
|
-
concurrency tickets
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
**How it was tested.** Official MongoDB builds of each version were run
|
|
288
|
-
`mdbkit lab`
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
+
is left out. It is never guessed. Where MongoDB moved a metric between
|
|
305
|
+
versions (concurrency tickets, checkpoint times, eviction), mdbkit reads both
|
|
306
|
+
the old and the new location.
|
|
307
|
+
|
|
308
|
+
**How it was tested.** Official MongoDB builds of each version were run
|
|
309
|
+
with `mdbkit lab` as a three-node replica set, a standalone and (6.0, 7.0,
|
|
310
|
+
8.0 and 9.0) a sharded cluster with a config server, two shards and a
|
|
311
|
+
mongos. Then each one was broken on purpose, in the ways mdbkit is meant to
|
|
312
|
+
spot:
|
|
313
|
+
|
|
314
|
+
* unindexed queries, sorts that spill to disk, writes blocked behind
|
|
315
|
+
`fsyncLock` and long-running operations;
|
|
316
|
+
* a clean restart, and a primary killed with `kill -9` (the crash, the
|
|
317
|
+
failover and the recovery);
|
|
318
|
+
* a stepdown, and a connection storm of 300 connections at once;
|
|
319
|
+
* flow control, with both secondaries frozen by `fsyncLock` while the
|
|
320
|
+
primary took writes;
|
|
321
|
+
* cache pressure from a working set four times the cache, and a checkpoint
|
|
322
|
+
that ran for over a minute (the process frozen mid-checkpoint);
|
|
323
|
+
* chunk migrations (one failing on purpose), the balancer moving data on its
|
|
324
|
+
own, and a shard killed while queries ran.
|
|
325
|
+
|
|
326
|
+
Every mdbkit command was run on the resulting logs, `diagnostic.data`,
|
|
327
|
+
serverStatus, explain, `getLog` and `$indexStats` output, and compared with
|
|
328
|
+
what the servers did. Trimmed copies of that output are in
|
|
329
|
+
[`tests/fixtures/real/`](tests/fixtures/real/) and run with every test.
|
|
304
330
|
|
|
305
331
|
If mdbkit misreads a line from your deployment, please
|
|
306
332
|
[open an issue](../../issues) with the line (redact as you like).
|
|
@@ -357,12 +383,15 @@ mdbkit triage mongod.log --window 0 # the whole file
|
|
|
357
383
|
mdbkit triage mongod.log --report incident.html # something to attach to a ticket
|
|
358
384
|
```
|
|
359
385
|
|
|
360
|
-
|
|
361
|
-
error clusters, slow-query peaks, startup
|
|
362
|
-
waiting rather than working (8.0+),
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
386
|
+
Crashes and restarts, elections, connection storms, flow control, hot
|
|
387
|
+
collections, index builds, error clusters, slow-query peaks, startup
|
|
388
|
+
misconfiguration, time spent waiting rather than working (8.0+),
|
|
389
|
+
still-running operations (8.3+), and on sharded clusters scatter-gather
|
|
390
|
+
queries, chunk migrations and unreachable shards — plus disk, memory, CPU,
|
|
391
|
+
cache pressure and checkpoints from FTDC when run on the database host.
|
|
392
|
+
Every finding ends with the next command to run. A shutdown followed by the
|
|
393
|
+
server listening again is reported as a restart (WARN); a start with no
|
|
394
|
+
clean shutdown before it, as a crash (CRIT).
|
|
366
395
|
|
|
367
396
|
### 4. Did my change actually help?
|
|
368
397
|
|
|
@@ -452,7 +481,7 @@ last 1440 minutes of each log | 7.8 GiB RAM (this machine)
|
|
|
452
481
|
[CRIT] Cache sizes vs RAM: WiredTiger caches add up to 11.8 GiB, 150% of 7.8 GiB RAM (this machine).
|
|
453
482
|
[CRIT] Instances that crashed: 1 instance(s) started after an unclean stop (crash, kill -9 or OOM kill).
|
|
454
483
|
- vm:29021: 1 unclean start(s)
|
|
455
|
-
[WARN] Default cache size on a shared host: 3 of 8 instances run with the default WiredTiger cache (cacheSizeGB not set). [...]
|
|
484
|
+
[WARN] Default cache size on a shared host: 3 of 8 mongod instances run with the default WiredTiger cache (cacheSizeGB not set). [...]
|
|
456
485
|
|
|
457
486
|
instance set version role cache starts crashes slow ops slow time waiting worst first issue
|
|
458
487
|
-------- ---- ------- ---------- ------- ------ ------- -------- --------- ------- ----- --------------------------
|
|
@@ -468,6 +497,60 @@ the default WiredTiger cache, which assumes the machine is its alone; the
|
|
|
468
497
|
caches add up to several times the RAM and the OOM killer picks off
|
|
469
498
|
instances. (Output above is from a real 8-instance test host.)
|
|
470
499
|
|
|
500
|
+
### 8. Is my sharded cluster sending queries to every shard?
|
|
501
|
+
|
|
502
|
+
```bash
|
|
503
|
+
mdbkit queries /var/log/mongodb/mongos.log # how each query was routed
|
|
504
|
+
mdbkit triage /var/log/mongodb/mongos.log # scatter-gather, unreachable shards
|
|
505
|
+
mdbkit triage /var/log/mongodb/shard1.log # chunk migrations and why they failed
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
```
|
|
509
|
+
namespace op count cumMs mean max shards to all shard wait shape
|
|
510
|
+
shop.orders find 50 520ms 10ms 28ms 2 50/50 97% {createdAt:gt, status:eq} sort:{createdAt:-1}
|
|
511
|
+
shop.orders aggregate 20 291ms 14ms 20ms 2 20/20 90% {status:eq}
|
|
512
|
+
shop.orders find 80 19ms 0ms 3ms 1 0/80 21% {customerId:eq}
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
The router's log shows which query shapes went to every shard (usually no
|
|
516
|
+
shard key in the filter) and which went to one. The shards' logs show chunk
|
|
517
|
+
migrations, how much they moved and why any failed; the config server's
|
|
518
|
+
shows balancer errors. Plans live on the shards, so run `queries` and
|
|
519
|
+
`advise` on a shard log for index advice. (Output from a real 8.0 cluster,
|
|
520
|
+
sharded on `customerId`.)
|
|
521
|
+
|
|
522
|
+
### 9. Which indexes are not earning their keep?
|
|
523
|
+
|
|
524
|
+
```bash
|
|
525
|
+
mdbkit export-script indexes > export_indexes.js
|
|
526
|
+
mongosh --quiet "mongodb://your_db_host:27017/" --eval "$(cat export_indexes.js)" > indexes.json
|
|
527
|
+
mdbkit indexes indexes.json
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
```
|
|
531
|
+
exported from: a mongos (usage from each shard's primary)
|
|
532
|
+
|
|
533
|
+
Unused since the counters started (1)
|
|
534
|
+
shop.orders customerId_1_status_1 { customerId: 1, status: 1 } — 0 use(s)
|
|
535
|
+
no recorded use since the counters started
|
|
536
|
+
test safely: db.getSiblingDB("shop").getCollection("orders").hideIndex("customerId_1_status_1")
|
|
537
|
+
|
|
538
|
+
Redundant: a prefix of another index (1)
|
|
539
|
+
shop.orders status_1 { status: 1 } — 20 use(s)
|
|
540
|
+
its key is a prefix of status_1_createdAt_-1 { status: 1, createdAt: -1 }, which can serve the same queries
|
|
541
|
+
test safely: db.getSiblingDB("shop").getCollection("orders").hideIndex("status_1")
|
|
542
|
+
|
|
543
|
+
Unused, but not a candidate (1)
|
|
544
|
+
shop.orders createdAt_1 { createdAt: 1 } — 0 use(s)
|
|
545
|
+
unused for queries, but it is a TTL index: the TTL monitor uses it, which the counters do not show
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
Every index costs write time, memory and disk. This lists the ones with no
|
|
549
|
+
recorded use and the ones another index already covers, and explains the
|
|
550
|
+
ones it deliberately leaves alone (unique, TTL, hidden, the shard key's
|
|
551
|
+
index). It never says "drop": `hideIndex` is the reversible test. (Output
|
|
552
|
+
from a real 8.0 cluster, exported through mongos.)
|
|
553
|
+
|
|
471
554
|
---
|
|
472
555
|
|
|
473
556
|
## Running it on a schedule
|
|
@@ -542,6 +625,8 @@ mdbkit lab start # 3-node replica set on 127.0.0.1:28110-2811
|
|
|
542
625
|
mdbkit lab seed # 50k documents + a deliberately mixed workload
|
|
543
626
|
mdbkit queries $(mdbkit lab logs | head -1)
|
|
544
627
|
mdbkit lab destroy --yes # remove it entirely
|
|
628
|
+
|
|
629
|
+
mdbkit lab start --shards 2 # or a sharded cluster: config server, 2 shards, mongos
|
|
545
630
|
```
|
|
546
631
|
|
|
547
632
|
It binds to localhost only, uses ports far from 27017 so it can never be
|
|
@@ -574,8 +659,11 @@ cat mongod.log | mdbkit queries - # stdin
|
|
|
574
659
|
|
|
575
660
|
### `mdbkit loginfo <log>`
|
|
576
661
|
|
|
577
|
-
Overall log summary: server version,
|
|
578
|
-
|
|
662
|
+
Overall log summary: server version, what wrote the log (replica set
|
|
663
|
+
member, standalone, mongos, shard or config server, and its replica set),
|
|
664
|
+
host, restarts, connections accepted, slow-query count, still-running
|
|
665
|
+
operations (8.3+), chunk migrations (on a shard), warning/error counts, and a
|
|
666
|
+
per-component line breakdown.
|
|
579
667
|
|
|
580
668
|
| Option | Description |
|
|
581
669
|
|---|---|
|
|
@@ -600,6 +688,7 @@ query with different parameters is counted once.
|
|
|
600
688
|
| `--min-ms N` | 0 | Ignore operations faster than N milliseconds |
|
|
601
689
|
| `--include-system` | off | Include internal `admin`/`config`/`local` namespaces (hidden by default — they are server housekeeping, not your workload) |
|
|
602
690
|
| `--report FILE` | | Write a shareable `.md` or `.html` report instead (see [Shareable reports](#shareable-reports----report-file)) |
|
|
691
|
+
| `--shape N` or `--shape HASH` | | Full detail on one shape: row N of the table, or the shape with this `queryHash`, `planCacheShapeHash`, `planCacheKey` or `queryShapeHash` |
|
|
603
692
|
| `--json` | | Machine-readable output |
|
|
604
693
|
|
|
605
694
|
**Reading the columns:**
|
|
@@ -611,6 +700,7 @@ query with different parameters is counted once.
|
|
|
611
700
|
| `docsEx` | Documents examined, summed across all occurrences |
|
|
612
701
|
| `scan` | Documents examined per document returned. `1:1` is ideal; `3444:1` means a missing or weak index |
|
|
613
702
|
| `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 |
|
|
703
|
+
| `queryHash` | MongoDB's own identifier for the shape, from the log (called `planCacheShapeHash` from 8.0, which logs both names). `+N` = mongod gave this shape N more. `-` = the log lines carry none (inserts, some updates, and 8.0+ `EXPRESS` lookups, which skip the planner) |
|
|
614
704
|
| `shape` | Fields and operators queried, with the sort |
|
|
615
705
|
|
|
616
706
|
Two kinds of row are worth knowing about. A `getMore(find)` or
|
|
@@ -620,12 +710,21 @@ included even though no index can speed up an insert: a slow insert is still
|
|
|
620
710
|
latency your application saw, and on 8.0+ the `--shape` view says whether it
|
|
621
711
|
was executing or waiting (on locks, flow control or write concern).
|
|
622
712
|
|
|
713
|
+
**On a mongos (router) log** the table changes: a router records how each
|
|
714
|
+
query was routed but not its plan (the shards have that), so `docsEx`,
|
|
715
|
+
`scan` and `plan` give way to `shards` (how many shards each execution went
|
|
716
|
+
to), `to all` (executions sent to every shard: scatter-gather) and
|
|
717
|
+
`shard wait` (the share of time spent waiting for the shards). Cluster
|
|
718
|
+
administration commands (`moveRange`, `shardCollection`, ...) are left out;
|
|
719
|
+
`triage` on the shard logs reports migrations.
|
|
720
|
+
|
|
623
721
|
```bash
|
|
624
722
|
mdbkit queries mongod.log
|
|
625
723
|
mdbkit queries mongod.log --sort scanRatio --limit 10
|
|
626
724
|
mdbkit queries mongod.log --min-ms 500 --json
|
|
627
725
|
mdbkit queries "mongod.log*" # rotated logs as one stream
|
|
628
726
|
mdbkit queries mongod.log --shape 1 # drill into the worst offender
|
|
727
|
+
mdbkit queries mongod.log --shape 0F877C7D # the same, by its queryHash
|
|
629
728
|
```
|
|
630
729
|
|
|
631
730
|
`--shape N` expands one row of the table. On an 8.0+ log it also shows where
|
|
@@ -659,17 +758,37 @@ resources
|
|
|
659
758
|
disk spills : 159 (13.6 GiB written)
|
|
660
759
|
CPU time : 5.5m total
|
|
661
760
|
|
|
662
|
-
server identifiers
|
|
761
|
+
server identifiers (find this shape's log lines, plan cache entry or query settings)
|
|
762
|
+
queryHash : 0F877C7D
|
|
763
|
+
(named planCacheShapeHash from 8.0, which logs both)
|
|
764
|
+
planCacheKey : 8F21BC04
|
|
663
765
|
queryShapeHash : BDC6B796B132EBAF671210F40FC5155C05ED250F79996E68DC6C620CBD8972AE
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
766
|
+
the full log lines : mdbkit filter <log> --query-hash 0F877C7D --last 5
|
|
767
|
+
as runnable explain: mdbkit filter <log> --query-hash 0F877C7D --last 1 --as-explain
|
|
768
|
+
plan cache entry : db.getSiblingDB("shop").getCollection("events").aggregate([{$planCacheStats: {}}, {$match: {queryHash: "0F877C7D"}}])
|
|
769
|
+
(run on the member that logged it; only queries that had more than one candidate plan are cached)
|
|
770
|
+
pin or block this shape without a code change (8.0+):
|
|
771
|
+
db.adminCommand({setQuerySettings: "BDC6B796...", settings: {...}})
|
|
667
772
|
```
|
|
668
773
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
774
|
+
**From a shape back to the query.** The table groups thousands of log lines
|
|
775
|
+
into a few shapes; the hashes take you back to the lines themselves.
|
|
776
|
+
`queryHash` (8 characters) is in the slow-query lines of operations that
|
|
777
|
+
went through the query planner, on mongod and on mongos (checked on 6.0 to
|
|
778
|
+
9.0); for a find, the mongos value matches the shards' (checked on 9.0). `filter --query-hash` prints those
|
|
779
|
+
lines, or rebuilds the latest as a runnable `explain`:
|
|
780
|
+
|
|
781
|
+
```bash
|
|
782
|
+
mdbkit queries mongod.log # note the queryHash of the shape you want
|
|
783
|
+
mdbkit filter mongod.log --query-hash 0F877C7D --last 5 # its full log lines
|
|
784
|
+
mdbkit filter mongod.log --query-hash 0F877C7D --last 1 --as-explain
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
The same `queryHash` finds the shape's plan cache entry (checked on real
|
|
788
|
+
7.0 and 9.0 servers), and the 8.0+ `queryShapeHash` is the value MongoDB
|
|
789
|
+
shows in `explain`, the profiler, `$currentOp` and `$queryStats`, and that
|
|
790
|
+
`setQuerySettings` takes. mdbkit only prints those commands. It never runs
|
|
791
|
+
them.
|
|
673
792
|
|
|
674
793
|
---
|
|
675
794
|
|
|
@@ -716,13 +835,15 @@ it chains with other tools (including mdbkit itself).
|
|
|
716
835
|
|
|
717
836
|
| Option | Description |
|
|
718
837
|
|---|---|
|
|
719
|
-
| `--component NAME` | `COMMAND`, `NETWORK`, `REPL`, `STORAGE`, `INDEX`, `WRITE`, `QUERY`, `CONTROL`, … |
|
|
838
|
+
| `--component NAME` | `COMMAND`, `NETWORK`, `REPL`, `ELECTION`, `STORAGE`, `INDEX`, `WRITE`, `QUERY`, `SHARDING`, `CONTROL`, … |
|
|
720
839
|
| `--severity S` | `I` info, `W` warning, `E` error, `F` fatal |
|
|
721
840
|
| `--ns NAMESPACE` | Exact namespace, e.g. `shop.orders` |
|
|
722
841
|
| `--slow N` | Only operations with `durationMillis` >= N |
|
|
723
842
|
| `--from TIMESTAMP` | Lower time bound (inclusive) |
|
|
724
843
|
| `--to TIMESTAMP` | Upper time bound (inclusive) |
|
|
725
844
|
| `--msg TEXT` | Substring match on the message field |
|
|
845
|
+
| `--failed` | Only operations that ended in an error (logged with an `errName`) |
|
|
846
|
+
| `--query-hash HASH` | Only operations with this `queryHash`, `planCacheShapeHash`, `planCacheKey` or `queryShapeHash` (as `queries` shows them; case ignored, and a `queryShapeHash` may be shortened to its first 8+ characters) |
|
|
726
847
|
| `--limit N` | Print only the **first** N matches |
|
|
727
848
|
| `--last N` | Print only the **last** N matches — usually what you want during an incident |
|
|
728
849
|
| `--as-explain` | Rebuild each matching slow query as a runnable `mongosh` `.explain()` command instead of printing the raw log line |
|
|
@@ -743,7 +864,7 @@ it chains with other tools (including mdbkit itself).
|
|
|
743
864
|
mdbkit filter mongod.log --severity E --last 20 # errors (most recent 20)
|
|
744
865
|
mdbkit filter mongod.log --severity F # fatal — always investigate
|
|
745
866
|
mdbkit filter mongod.log --severity W --last 50 # warnings
|
|
746
|
-
mdbkit filter mongod.log --component
|
|
867
|
+
mdbkit filter mongod.log --component ELECTION # elections and stepdowns
|
|
747
868
|
mdbkit filter mongod.log --slow 500 --ns shop.orders --limit 50
|
|
748
869
|
mdbkit filter mongod.log --from 2026-07-01T14:30:00+04:00 --to 2026-07-01T15:00:00+04:00
|
|
749
870
|
mdbkit filter mongod.log --slow 100 | mdbkit queries -
|
|
@@ -758,8 +879,8 @@ mdbkit filter mongod.log --ns shop.orders --slow 500 --last 3 --as-explain
|
|
|
758
879
|
|
|
759
880
|
# Or produce a runnable script, get the plan, and analyze it
|
|
760
881
|
mdbkit filter mongod.log --slow 500 --last 1 --as-explain --explain-script > q.js
|
|
761
|
-
mongosh --quiet --host your_db_host --username your_username
|
|
762
|
-
--password your_password --authenticationDatabase admin
|
|
882
|
+
mongosh --quiet --host your_db_host --username your_username \
|
|
883
|
+
--password your_password --authenticationDatabase admin \
|
|
763
884
|
--eval "$(cat q.js)" > explain.json
|
|
764
885
|
mdbkit explain explain.json
|
|
765
886
|
```
|
|
@@ -814,13 +935,13 @@ help — a candidate index from the same advisor engine.
|
|
|
814
935
|
|
|
815
936
|
```bash
|
|
816
937
|
# 1. Capture the plan (adjust host/credentials for your deployment)
|
|
817
|
-
mongosh --quiet
|
|
818
|
-
--host your_db_host
|
|
819
|
-
--port 27017
|
|
820
|
-
--username your_username
|
|
821
|
-
--password your_password
|
|
822
|
-
--authenticationDatabase admin
|
|
823
|
-
--eval 'EJSON.stringify(db.getSiblingDB("shop").orders.find({status:"open"}).sort({ts:-1}).explain("executionStats"))'
|
|
938
|
+
mongosh --quiet \
|
|
939
|
+
--host your_db_host \
|
|
940
|
+
--port 27017 \
|
|
941
|
+
--username your_username \
|
|
942
|
+
--password your_password \
|
|
943
|
+
--authenticationDatabase admin \
|
|
944
|
+
--eval 'EJSON.stringify(db.getSiblingDB("shop").orders.find({status:"open"}).sort({ts:-1}).explain("executionStats"))' \
|
|
824
945
|
> explain.json
|
|
825
946
|
|
|
826
947
|
# 2. Analyze it
|
|
@@ -851,7 +972,10 @@ one screen that says what happened, how bad it is, and where to look next.
|
|
|
851
972
|
| `--window N` | 60 | Analyze the last N minutes of log time; `0` = the whole file |
|
|
852
973
|
| `--dbpath PATH` | auto | Override the data directory used for the disk check |
|
|
853
974
|
| `--no-sysprobe` | off | Skip local disk/memory/CPU probes — use when analyzing a log copied off the host |
|
|
854
|
-
| `--ftdc PATH` | | `diagnostic.data` directory — adds CPU, memory, cache,
|
|
975
|
+
| `--ftdc PATH` | | `diagnostic.data` directory — adds CPU, memory, cache, checkpoint, eviction, flow-control and connection history from MongoDB's own recorder. Found automatically when the log is from this host (a mongos keeps it next to its log) |
|
|
976
|
+
| `--oslog FILE...` | | System log(s): OOM kills, file-descriptor limits and I/O errors that the mongod log cannot record |
|
|
977
|
+
| `--only LEVELS` | | Show only these severities, e.g. `--only CRIT,WARN` |
|
|
978
|
+
| `--exit-code` | | Exit 2 on CRIT, 1 on WARN, else 0 |
|
|
855
979
|
| `--report FILE` | | Write a shareable `.md` or `.html` report instead of terminal output |
|
|
856
980
|
| `--json` | | Machine-readable output |
|
|
857
981
|
|
|
@@ -867,8 +991,33 @@ mdbkit triage mongod.log --window 0 --no-sysprobe
|
|
|
867
991
|
with no clean shutdown before it is a CRIT, because that is what a crash,
|
|
868
992
|
`kill -9` or OOM kill looks like. mongod itself records whether its previous
|
|
869
993
|
shutdown was clean, so mdbkit can tell even when the crash happened before
|
|
870
|
-
the log you are reading begins.
|
|
871
|
-
|
|
994
|
+
the log you are reading begins.
|
|
995
|
+
|
|
996
|
+
**Elections.** An election because a member saw no primary is a CRIT: the
|
|
997
|
+
primary was lost (crash, kill, hang or network). A stepdown command ("step
|
|
998
|
+
up request") or a higher-priority member taking over is a WARN, worded as
|
|
999
|
+
probably deliberate. The first election of a newly initiated replica set is
|
|
1000
|
+
INFO, not instability.
|
|
1001
|
+
|
|
1002
|
+
**Flow control, cache pressure and checkpoints.** Flow control is read from
|
|
1003
|
+
the log (MongoDB warns every 10 seconds while it throttles writes) and from
|
|
1004
|
+
FTDC (how long it was engaged and how long writers waited). Cache pressure
|
|
1005
|
+
comes from FTDC: how long the cache sat past the points where application
|
|
1006
|
+
threads must help evict (95% full or 20% dirty), and how much time they
|
|
1007
|
+
spent evicting in the busiest minute. A slow checkpoint is a WARN past 60
|
|
1008
|
+
seconds; FTDC records every checkpoint's duration, and MongoDB 8.3+ also
|
|
1009
|
+
logs one that runs past 20 seconds. Each of these was checked on real 6.0,
|
|
1010
|
+
7.0, 8.0 and 9.0 servers driven into that state.
|
|
1011
|
+
|
|
1012
|
+
**Sharded clusters.** On a mongos log, `triage` reports queries sent to every
|
|
1013
|
+
shard (scatter-gather), time spent waiting on the shards, routing-table
|
|
1014
|
+
refreshes, and shards or members the router could not reach. On a shard's
|
|
1015
|
+
log it reports chunk migrations (how many, how much data, and why any
|
|
1016
|
+
failed, e.g. waiting for the range deleter); on the config server's,
|
|
1017
|
+
balancer errors. On any log, **failed operations** on your collections (a
|
|
1018
|
+
query or write that ended in an error such as
|
|
1019
|
+
`FailedToSatisfyReadPreference` or `MaxTimeMSExpired`) are grouped by
|
|
1020
|
+
error; `mdbkit filter <log> --failed` prints them.
|
|
872
1021
|
|
|
873
1022
|
**Hosts running several mongods.** `triage` reads one instance's log; don't
|
|
874
1023
|
pass several instances' logs to it, because several files are read as one
|
|
@@ -910,7 +1059,9 @@ startup line.
|
|
|
910
1059
|
**Per instance:** replica set, version, role, WiredTiger cache size, starts
|
|
911
1060
|
and crashes (unclean stops), slow operations and their total time, the share
|
|
912
1061
|
of that time spent waiting (8.0+), and its worst finding from the same
|
|
913
|
-
detectors `triage` uses.
|
|
1062
|
+
detectors `triage` uses. Shard and config server members are labelled as
|
|
1063
|
+
such, and a mongos on the same host gets a line of its own (it has no cache,
|
|
1064
|
+
so it is left out of the cache total).
|
|
914
1065
|
|
|
915
1066
|
**For the host:**
|
|
916
1067
|
|
|
@@ -983,7 +1134,7 @@ not encrypted; mdbkit decodes it offline.
|
|
|
983
1134
|
| `--all` | off | Analyze the entire history (see the performance note below) |
|
|
984
1135
|
| `--metric LABEL` | all | Restrict to one metric (repeatable), e.g. `--metric conns.current` |
|
|
985
1136
|
| `--step SECONDS` | 60 | Timeline bucket size |
|
|
986
|
-
| `--from` / `--to` | | Explicit time bounds (same formats as `filter`) |
|
|
1137
|
+
| `--from` / `--to` | | Explicit time bounds, UTC unless the value has an offset (same formats as `filter`) |
|
|
987
1138
|
| `--json` | | Machine-readable output |
|
|
988
1139
|
|
|
989
1140
|
**Performance note.** `diagnostic.data` can hold weeks of per-second samples —
|
|
@@ -1002,12 +1153,18 @@ mdbkit ftdc export diagnostic.data > metrics.csv
|
|
|
1002
1153
|
|
|
1003
1154
|
In `timeline`, gauges (connections, cache bytes, tickets) show the peak in
|
|
1004
1155
|
each bucket and cumulative counters (`ops.*`, `sys.cpu.*`) show their rate
|
|
1005
|
-
per second over it.
|
|
1156
|
+
per second over it. FTDC records time in UTC, and these commands show it as
|
|
1157
|
+
UTC; `triage --ftdc` converts it to the log's own time zone so the two line
|
|
1158
|
+
up.
|
|
1006
1159
|
|
|
1007
1160
|
Metric labels include `ops.*` (insert/query/update/delete/getmore/command),
|
|
1008
1161
|
`conns.current`, `conns.available`, `queue.readers`, `queue.writers`,
|
|
1009
1162
|
`cache.usedBytes`, `cache.maxBytes`, `cache.dirtyBytes`, `tickets.*`,
|
|
1010
|
-
`
|
|
1163
|
+
`checkpoint.lastMs`, `evict.appThreadMicros`, `flowControl.*`,
|
|
1164
|
+
`mem.residentMB`, and on Linux `sys.cpu.*` and `sys.mem.availableKB`. The
|
|
1165
|
+
same labels work across versions where MongoDB renamed the underlying
|
|
1166
|
+
statistic (checked on 6.0 to 9.0), and on 8.0+ shard servers and mongos,
|
|
1167
|
+
which group their metrics by role.
|
|
1011
1168
|
|
|
1012
1169
|
The data directory can be copied off the host and analyzed elsewhere — it
|
|
1013
1170
|
contains metrics only, never document contents.
|
|
@@ -1032,16 +1189,17 @@ Markdown output looks like this:
|
|
|
1032
1189
|
```markdown
|
|
1033
1190
|
# MongoDB incident triage
|
|
1034
1191
|
|
|
1035
|
-
*window 2026-07-01 08:
|
|
1192
|
+
*window 2026-07-01 08:29 -> 09:29 · generated 2026-07-01 09:31*
|
|
1036
1193
|
|
|
1037
1194
|
## Findings
|
|
1038
1195
|
|
|
1039
|
-
- **[CRIT] Replica set instability** —
|
|
1040
|
-
- Starting an election, since we've seen no PRIMARY in election timeout period
|
|
1041
|
-
-
|
|
1042
|
-
-
|
|
1043
|
-
|
|
1044
|
-
-
|
|
1196
|
+
- **[CRIT] Replica set instability** — 2 election/stepdown event(s); at least once a member saw no primary and called an election, which is what losing the primary (crash, kill, hang or network) looks like.
|
|
1197
|
+
- 08:50:32 Starting an election, since we've seen no PRIMARY in election timeout period
|
|
1198
|
+
- 08:50:34 Election succeeded, assuming primary role
|
|
1199
|
+
- *next:* `Find why the primary went away at the first timestamp: its own log (mdbkit triage on it), then the OS log (mdbkit oslog) for OOM kills or restarts.`
|
|
1200
|
+
- **[WARN] Connection storm** — 1 minute(s) at >= 60 new connections/min (baseline median 0/min); peak 220 at 08:49.
|
|
1201
|
+
- 10.20.9.77: 220 in the peak minute
|
|
1202
|
+
- *next:* `Identify the client: mdbkit connections <log> — look for pool misconfiguration or crash-loop reconnects.`
|
|
1045
1203
|
- **[OK] Errors** — No error/fatal severity lines in window.
|
|
1046
1204
|
```
|
|
1047
1205
|
|
|
@@ -1090,12 +1248,12 @@ or rehearsing a demo. This is the only command that starts external
|
|
|
1090
1248
|
processes; see [SECURITY.md](SECURITY.md) for exactly how it is bounded.
|
|
1091
1249
|
|
|
1092
1250
|
Requires `mongod` on your `PATH` (and `mongosh` to initiate the replica set
|
|
1093
|
-
and seed data). Linux and macOS.
|
|
1251
|
+
and seed data; a sharded lab also needs `mongos`). Linux and macOS.
|
|
1094
1252
|
|
|
1095
1253
|
| Action | What it does |
|
|
1096
1254
|
|---|---|
|
|
1097
|
-
| `start` | Create and start a replica set, print the connection string and log paths |
|
|
1098
|
-
| `seed` | Insert sample data and run a workload with deliberately interesting queries |
|
|
1255
|
+
| `start` | Create and start a replica set (or standalone, or sharded cluster), print the connection string and log paths. On an existing lab, start the nodes that are down, with their data and ports (options that would make a different lab are refused) |
|
|
1256
|
+
| `seed` | Insert sample data and run a workload with deliberately interesting queries (`--workload-only`: just the queries, on the data already there) |
|
|
1099
1257
|
| `status` | Show ports, pids and whether each node is running |
|
|
1100
1258
|
| `logs` | Print the log file paths, ready to pipe into other commands |
|
|
1101
1259
|
| `stop` | Stop the nodes, keep the data |
|
|
@@ -1104,11 +1262,13 @@ and seed data). Linux and macOS.
|
|
|
1104
1262
|
| Option | Default | Description |
|
|
1105
1263
|
|---|---|---|
|
|
1106
1264
|
| `--dir PATH` | `~/.mdbkit-lab` | Where the lab lives |
|
|
1107
|
-
| `--nodes N` | 3 | Replica set size |
|
|
1265
|
+
| `--nodes N` | 3 | Replica set size (with `--shards`: each shard's replica set, default 1) |
|
|
1266
|
+
| `--shards N` | | A sharded cluster with N shards, a config server and a mongos |
|
|
1108
1267
|
| `--port N` | 28110 | Base port — deliberately far from 27017 |
|
|
1109
1268
|
| `--slowms N` | 0 | Log every operation, which is what makes the log worth reading |
|
|
1110
1269
|
| `--standalone` | off | Single node, no replica set |
|
|
1111
1270
|
| `--docs N` | 50000 | Documents inserted by `seed` |
|
|
1271
|
+
| `--workload-only` | | `seed` runs the queries again on the data already there |
|
|
1112
1272
|
| `--yes` | | Confirm `destroy` |
|
|
1113
1273
|
|
|
1114
1274
|
**The full loop:**
|
|
@@ -1132,11 +1292,25 @@ mdbkit lab logs
|
|
|
1132
1292
|
# /home/you/.mdbkit-lab/node1/mongod.log
|
|
1133
1293
|
# /home/you/.mdbkit-lab/node2/mongod.log
|
|
1134
1294
|
|
|
1135
|
-
mdbkit queries $(mdbkit lab logs | head -1) #
|
|
1295
|
+
mdbkit queries $(mdbkit lab logs | head -1) # node0, the preferred primary
|
|
1136
1296
|
mdbkit triage $(mdbkit lab logs) # all three as one stream
|
|
1137
1297
|
mdbkit loginfo $(mdbkit lab logs | sed -n 2p) # a specific secondary
|
|
1138
1298
|
```
|
|
1139
1299
|
|
|
1300
|
+
**A sharded cluster**: a config server, N single-node shards (`--nodes 3`
|
|
1301
|
+
makes each shard a three-node replica set) and a mongos. `seed` shards
|
|
1302
|
+
`shop.orders` on `customerId`, moves a range to every shard, then runs
|
|
1303
|
+
targeted and scatter-gather queries through mongos. `logs` lists the mongos
|
|
1304
|
+
log first:
|
|
1305
|
+
|
|
1306
|
+
```bash
|
|
1307
|
+
mdbkit lab start --shards 2 # config 28110, shards 28111-28112, mongos 28113
|
|
1308
|
+
mdbkit lab seed
|
|
1309
|
+
mdbkit queries $(mdbkit lab logs | head -1) # the router: shards per query
|
|
1310
|
+
mdbkit triage $(mdbkit lab logs | sed -n 3p) # a shard: migrations, its queries
|
|
1311
|
+
mdbkit lab destroy --yes
|
|
1312
|
+
```
|
|
1313
|
+
|
|
1140
1314
|
**A single node**, when you do not need replication. It starts faster, and
|
|
1141
1315
|
`start` works without `mongosh` (`seed` still needs it):
|
|
1142
1316
|
|
|
@@ -1167,22 +1341,39 @@ mdbkit lab start # back up with the same data
|
|
|
1167
1341
|
mdbkit lab status # ports, pids, running or not
|
|
1168
1342
|
```
|
|
1169
1343
|
|
|
1344
|
+
**Rehearse a failure.** Kill a node the way a crash or the OOM killer would,
|
|
1345
|
+
see what mdbkit makes of it, then bring it back. `start` on an existing lab
|
|
1346
|
+
starts only the nodes that are down, on their old ports:
|
|
1347
|
+
|
|
1348
|
+
```bash
|
|
1349
|
+
kill -9 $(cat ~/.mdbkit-lab/node0/mongod.pid) # the primary dies
|
|
1350
|
+
sleep 20 # the others elect a new one
|
|
1351
|
+
mdbkit lab start # node0 comes back
|
|
1352
|
+
mdbkit triage $(mdbkit lab logs) --window 0 # crash, failover, recovery
|
|
1353
|
+
```
|
|
1354
|
+
|
|
1170
1355
|
**A complete before/after experiment**, which is what `lab` is really for:
|
|
1171
1356
|
|
|
1172
1357
|
```bash
|
|
1173
1358
|
mdbkit lab start && mdbkit lab seed
|
|
1174
1359
|
cp $(mdbkit lab logs | head -1) before.log
|
|
1360
|
+
mongosh --port 28110 --quiet --eval 'db.adminCommand({logRotate: 1})' # start a fresh log
|
|
1175
1361
|
|
|
1176
1362
|
mongosh --port 28110 --eval \
|
|
1177
1363
|
'db.getSiblingDB("shop").orders.createIndex({status:1, createdAt:-1})'
|
|
1178
1364
|
|
|
1179
|
-
mdbkit lab seed
|
|
1365
|
+
mdbkit lab seed --workload-only # the same queries, now with the index
|
|
1180
1366
|
cp $(mdbkit lab logs | head -1) after.log
|
|
1181
1367
|
|
|
1182
1368
|
mdbkit compare before.log --after after.log
|
|
1183
1369
|
mdbkit lab destroy --yes
|
|
1184
1370
|
```
|
|
1185
1371
|
|
|
1372
|
+
`--workload-only` runs the queries again without reloading the data, so the
|
|
1373
|
+
index you added stays; a plain `seed` reloads and would drop it. Rotating the
|
|
1374
|
+
log keeps the second run's lines apart from the first's, because lab logs
|
|
1375
|
+
are appended to across restarts.
|
|
1376
|
+
|
|
1186
1377
|
`seed` runs indexed point lookups alongside deliberately unindexed queries —
|
|
1187
1378
|
an equality-plus-range-plus-sort with no supporting index, an aggregation
|
|
1188
1379
|
that scans the collection, and updates whose predicate has no index — so the
|
|
@@ -1191,8 +1382,9 @@ log immediately contains something worth analysing.
|
|
|
1191
1382
|
**Safety.** The lab binds to `127.0.0.1` only, refuses to use or delete any
|
|
1192
1383
|
directory it did not create, and never touches a MongoDB it did not start.
|
|
1193
1384
|
Before it signals a process it checks that the pid still belongs to one of
|
|
1194
|
-
its own `mongod`s
|
|
1195
|
-
stale pid file can never kill something
|
|
1385
|
+
its own `mongod`s or its `mongos` (the command line names the lab's data
|
|
1386
|
+
directory or log file), so a stale pid file can never kill something
|
|
1387
|
+
unrelated. `destroy` refuses to
|
|
1196
1388
|
delete data while a lab node is still running. If a port is already taken it
|
|
1197
1389
|
says so before starting anything. If a start fails halfway, the lab is left
|
|
1198
1390
|
in a state `mdbkit lab destroy --yes` can clean up, and the error says so.
|
|
@@ -1331,19 +1523,59 @@ duration moving by more than 20%.
|
|
|
1331
1523
|
|
|
1332
1524
|
---
|
|
1333
1525
|
|
|
1334
|
-
### `mdbkit
|
|
1526
|
+
### `mdbkit indexes <file>...`
|
|
1527
|
+
|
|
1528
|
+
Unused and redundant indexes, from what `mdbkit export-script indexes`
|
|
1529
|
+
exported (index definitions plus `$indexStats` usage counters).
|
|
1530
|
+
|
|
1531
|
+
| Option | Default | Description |
|
|
1532
|
+
|---|---|---|
|
|
1533
|
+
| `--ns NAMESPACE` | all | Only this collection |
|
|
1534
|
+
| `--min-days N` | 7 | Warn when the usage counters cover fewer days than this |
|
|
1535
|
+
| `--exit-code` | | Exit 1 when there is an unused or redundant index |
|
|
1536
|
+
| `--json` | | Machine-readable output |
|
|
1537
|
+
|
|
1538
|
+
```bash
|
|
1539
|
+
mdbkit indexes indexes.json
|
|
1540
|
+
mdbkit indexes primary.json secondary1.json secondary2.json # combine members
|
|
1541
|
+
mdbkit indexes indexes.json --ns shop.orders
|
|
1542
|
+
```
|
|
1543
|
+
|
|
1544
|
+
What it reports:
|
|
1545
|
+
|
|
1546
|
+
- **Unused:** no recorded use since the counters started.
|
|
1547
|
+
- **Redundant:** its key is a prefix of another index with the same
|
|
1548
|
+
collation, which can serve the same queries (`{a: 1}` when `{a: 1, b: 1}`
|
|
1549
|
+
exists). Partial, sparse and special (text, 2dsphere, hashed, wildcard)
|
|
1550
|
+
indexes are never treated as covering or covered.
|
|
1551
|
+
- **Not candidates:** `_id`, unique indexes (they enforce a constraint),
|
|
1552
|
+
TTL indexes (the TTL monitor's deletes do not count as use, checked on
|
|
1553
|
+
8.0 and 9.0), hidden indexes, and the index the shard key needs.
|
|
1554
|
+
|
|
1555
|
+
Usage counters are kept **per member** and **reset when a member restarts**.
|
|
1556
|
+
An index unused on the primary may serve reads on a secondary, and one used
|
|
1557
|
+
monthly can look unused after a week. So export from every member (or
|
|
1558
|
+
through mongos for a sharded cluster) and pass all the files, and check the
|
|
1559
|
+
counter window mdbkit prints. It never recommends dropping anything: it
|
|
1560
|
+
prints the `hideIndex` command, which makes the planner ignore the index
|
|
1561
|
+
while it is still maintained, so `unhideIndex` undoes it instantly.
|
|
1562
|
+
|
|
1563
|
+
---
|
|
1564
|
+
|
|
1565
|
+
### `mdbkit export-script {schema|indexes|serverstatus}`
|
|
1335
1566
|
|
|
1336
1567
|
Prints a small `mongosh` script to stdout. **mdbkit never connects to your
|
|
1337
1568
|
database**. You run these yourself, so you can read exactly what they do
|
|
1338
|
-
first.
|
|
1569
|
+
first. All are read-only. `schema` exports **field names and types only,
|
|
1339
1570
|
never document values**. `indexes` exports the index definitions from
|
|
1340
|
-
`getIndexes()
|
|
1341
|
-
values
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1571
|
+
`getIndexes()` (a partial index's filter expression can contain literal
|
|
1572
|
+
values) and, where your role allows `$indexStats`, how often each index has
|
|
1573
|
+
been used; through mongos it also records the shard keys.
|
|
1574
|
+
|
|
1575
|
+
`schema` and `indexes` cover **every database you can read** (`admin`,
|
|
1576
|
+
`config` and `local` skipped) and key collections by full namespace, so it
|
|
1577
|
+
does not matter which database mongosh connects to. To export one database
|
|
1578
|
+
only, set `ONLY_DB` at the top of the script. They write relaxed Extended
|
|
1347
1579
|
JSON, so 64-bit counters come out as plain numbers.
|
|
1348
1580
|
|
|
1349
1581
|
```bash
|
|
@@ -1359,41 +1591,49 @@ mdbkit export-script serverstatus > export_serverstatus.js
|
|
|
1359
1591
|
Terminal output is and will remain first-class — this tool is built for the
|
|
1360
1592
|
Linux box the database actually runs on.
|
|
1361
1593
|
|
|
1362
|
-
**
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
* **
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1594
|
+
**v0.8 is a long-term release.** Nothing further is scheduled. Bug reports
|
|
1595
|
+
are still read, and misread log lines are still the most useful thing to
|
|
1596
|
+
send.
|
|
1597
|
+
|
|
1598
|
+
**Shipped in v0.8.1:** the `queryHash` of each shape in the `queries`
|
|
1599
|
+
table, `queries --shape <hash>` and `filter --query-hash`, to go from a
|
|
1600
|
+
shape back to its full log lines
|
|
1601
|
+
([#1](https://github.com/saqibameen86/mdbkit/issues/1)). Checked against
|
|
1602
|
+
MongoDB 9.0.8, 8.3.17, 8.0.38 and 7.0.48, the newest patches in December
|
|
1603
|
+
2026.
|
|
1604
|
+
|
|
1605
|
+
**Shipped in v0.8:**
|
|
1606
|
+
|
|
1607
|
+
* **Sharded clusters.** mongos logs show how many shards each query shape
|
|
1608
|
+
went to, which ones went to all of them, and the time spent waiting on
|
|
1609
|
+
shards and refreshing routing tables. Shard and config server logs show
|
|
1610
|
+
chunk migrations (with the reason when one fails), the range deleter, the
|
|
1611
|
+
balancer's errors, unreachable shards and failed application operations.
|
|
1612
|
+
FTDC from 8.0+ shard servers and mongos decodes. `mdbkit lab --shards N`
|
|
1613
|
+
builds a cluster to try it on.
|
|
1614
|
+
* **`mdbkit indexes`:** unused and redundant indexes from `$indexStats`,
|
|
1615
|
+
across replica set members or shards, with the reversible `hideIndex`
|
|
1616
|
+
command rather than a drop.
|
|
1617
|
+
* **The beta detectors checked against real failures.** Elections and
|
|
1618
|
+
stepdowns, flow control, cache pressure and slow checkpoints were
|
|
1619
|
+
reproduced on real MongoDB 6.0, 7.0, 8.0 and 9.0 servers (a killed
|
|
1620
|
+
primary, a stepdown, a connection storm, frozen secondaries, a small
|
|
1621
|
+
cache under load, a checkpoint held up for a minute), so none is labelled
|
|
1622
|
+
beta any more. That turned up real bugs, now fixed: flow control was never
|
|
1623
|
+
spotted in the log, a failover soon after a set was created was taken for
|
|
1624
|
+
its set-up, a stepdown was invisible on the primary that stepped down, and
|
|
1625
|
+
every chunk migration looked like a shutdown on the receiving shard.
|
|
1626
|
+
* `filter --failed`, `lab start` restarting only the nodes that are down,
|
|
1627
|
+
`lab seed --workload-only`, and FTDC checkpoint and eviction metrics under
|
|
1628
|
+
their 8.0 names.
|
|
1629
|
+
|
|
1630
|
+
**Shipped before:** v0.7's `host` (hosts running many mongods); v0.6.1's
|
|
1631
|
+
testing against real servers; v0.6's 8.x/9.0 log fields and `audit`; v0.5's
|
|
1632
|
+
`oslog` and `serverstatus`; v0.4's `compare`; v0.3's `demo` and `lab`; v0.2's
|
|
1633
|
+
FTDC decoding, incident triage and shareable reports.
|
|
1634
|
+
|
|
1635
|
+
**Ideas, not scheduled:** jumbo chunks and balancer windows; slow oplog
|
|
1636
|
+
application on secondaries; `lab` on Windows.
|
|
1397
1637
|
|
|
1398
1638
|
## Bugs, feature requests, questions
|
|
1399
1639
|
|