mdbkit 0.6.1__tar.gz → 0.8.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.6.1/mdbkit.egg-info → mdbkit-0.8.0}/PKG-INFO +403 -129
- mdbkit-0.6.1/PKG-INFO → mdbkit-0.8.0/README.md +390 -152
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/__init__.py +1 -1
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/analysis.py +76 -1
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/cli.py +188 -40
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/filtering.py +4 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/ftdc.py +122 -11
- mdbkit-0.8.0/mdbkit/host.py +603 -0
- mdbkit-0.8.0/mdbkit/indexusage.py +319 -0
- mdbkit-0.8.0/mdbkit/lab.py +883 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/render.py +97 -11
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/scripts.py +28 -5
- mdbkit-0.8.0/mdbkit/sharding.py +402 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/triage.py +455 -98
- mdbkit-0.6.1/README.md → mdbkit-0.8.0/mdbkit.egg-info/PKG-INFO +426 -125
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit.egg-info/SOURCES.txt +9 -1
- {mdbkit-0.6.1 → mdbkit-0.8.0}/pyproject.toml +17 -4
- {mdbkit-0.6.1 → mdbkit-0.8.0}/tests/test_ftdc.py +1 -1
- mdbkit-0.8.0/tests/test_host.py +166 -0
- mdbkit-0.8.0/tests/test_indexes.py +185 -0
- mdbkit-0.8.0/tests/test_real_failures.py +181 -0
- mdbkit-0.8.0/tests/test_sharded.py +187 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/tests/test_triage.py +2 -2
- {mdbkit-0.6.1 → mdbkit-0.8.0}/tests/test_v060_hardening.py +82 -0
- mdbkit-0.8.0/tests/test_v080.py +151 -0
- mdbkit-0.6.1/mdbkit/lab.py +0 -542
- {mdbkit-0.6.1 → mdbkit-0.8.0}/LICENSE +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/advisor.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/audit.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/compare.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/demo.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/explain.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/oslog.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/parser.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/rebuild.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/report.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/serverstatus.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit/shelljson.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit.egg-info/dependency_links.txt +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit.egg-info/entry_points.txt +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit.egg-info/requires.txt +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/mdbkit.egg-info/top_level.txt +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/setup.cfg +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/tests/test_demo_lab.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/tests/test_explain.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/tests/test_mdbkit.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/tests/test_oslog_serverstatus.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/tests/test_real_servers.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/tests/test_rebuild_report.py +0 -0
- {mdbkit-0.6.1 → mdbkit-0.8.0}/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.0
|
|
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,13 @@ 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).
|
|
41
51
|
|
|
42
52
|
A spiritual successor to mtools' log tools, which never learned to read the
|
|
43
53
|
JSON log format introduced in 4.4.
|
|
@@ -267,40 +277,47 @@ updates — upgrades are always explicit.
|
|
|
267
277
|
## Compatibility
|
|
268
278
|
|
|
269
279
|
**Tested against (October 2026):** MongoDB **9.0.2**, **8.3.11**, **8.0.32**
|
|
270
|
-
(LTS)
|
|
271
|
-
|
|
272
|
-
|
|
280
|
+
(LTS), **7.0.43** (LTS) and **6.0.29**, the newest release in each series at
|
|
281
|
+
the time: replica sets and standalones on all five, and sharded clusters
|
|
282
|
+
(mongos, shards and config servers) on 6.0, 7.0, 8.0 and 9.0. mdbkit reads the structured JSON log format, so anything
|
|
283
|
+
from **4.4** onwards works; 4.2 and earlier wrote plain text logs and are not
|
|
284
|
+
supported.
|
|
273
285
|
|
|
274
286
|
| MongoDB | What mdbkit uses from it |
|
|
275
287
|
|---|---|
|
|
276
288
|
| 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 |
|
|
289
|
+
| 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
290
|
| 8.1+ | `<stage>Spills` / `<stage>SpilledBytes` (disk spills per stage) |
|
|
279
291
|
| 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
292
|
| 9.0 | Same log fields as 8.3. Adds a few fields mdbkit does not use yet (`delinquencyInfo`, `queues.ingress`) |
|
|
281
293
|
|
|
282
294
|
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
|
-
|
|
295
|
+
is left out. It is never guessed. Where MongoDB moved a metric between
|
|
296
|
+
versions (concurrency tickets, checkpoint times, eviction), mdbkit reads both
|
|
297
|
+
the old and the new location.
|
|
298
|
+
|
|
299
|
+
**How it was tested.** Official MongoDB builds of each version were run
|
|
300
|
+
with `mdbkit lab` as a three-node replica set, a standalone and (6.0, 7.0,
|
|
301
|
+
8.0 and 9.0) a sharded cluster with a config server, two shards and a
|
|
302
|
+
mongos. Then each one was broken on purpose, in the ways mdbkit is meant to
|
|
303
|
+
spot:
|
|
304
|
+
|
|
305
|
+
* unindexed queries, sorts that spill to disk, writes blocked behind
|
|
306
|
+
`fsyncLock` and long-running operations;
|
|
307
|
+
* a clean restart, and a primary killed with `kill -9` (the crash, the
|
|
308
|
+
failover and the recovery);
|
|
309
|
+
* a stepdown, and a connection storm of 300 connections at once;
|
|
310
|
+
* flow control, with both secondaries frozen by `fsyncLock` while the
|
|
311
|
+
primary took writes;
|
|
312
|
+
* cache pressure from a working set four times the cache, and a checkpoint
|
|
313
|
+
that ran for over a minute (the process frozen mid-checkpoint);
|
|
314
|
+
* chunk migrations (one failing on purpose), the balancer moving data on its
|
|
315
|
+
own, and a shard killed while queries ran.
|
|
316
|
+
|
|
317
|
+
Every mdbkit command was run on the resulting logs, `diagnostic.data`,
|
|
318
|
+
serverStatus, explain, `getLog` and `$indexStats` output, and compared with
|
|
319
|
+
what the servers did. Trimmed copies of that output are in
|
|
320
|
+
[`tests/fixtures/real/`](tests/fixtures/real/) and run with every test.
|
|
304
321
|
|
|
305
322
|
If mdbkit misreads a line from your deployment, please
|
|
306
323
|
[open an issue](../../issues) with the line (redact as you like).
|
|
@@ -357,12 +374,15 @@ mdbkit triage mongod.log --window 0 # the whole file
|
|
|
357
374
|
mdbkit triage mongod.log --report incident.html # something to attach to a ticket
|
|
358
375
|
```
|
|
359
376
|
|
|
360
|
-
|
|
361
|
-
error clusters, slow-query peaks, startup
|
|
362
|
-
waiting rather than working (8.0+),
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
377
|
+
Crashes and restarts, elections, connection storms, flow control, hot
|
|
378
|
+
collections, index builds, error clusters, slow-query peaks, startup
|
|
379
|
+
misconfiguration, time spent waiting rather than working (8.0+),
|
|
380
|
+
still-running operations (8.3+), and on sharded clusters scatter-gather
|
|
381
|
+
queries, chunk migrations and unreachable shards — plus disk, memory, CPU,
|
|
382
|
+
cache pressure and checkpoints from FTDC when run on the database host.
|
|
383
|
+
Every finding ends with the next command to run. A shutdown followed by the
|
|
384
|
+
server listening again is reported as a restart (WARN); a start with no
|
|
385
|
+
clean shutdown before it, as a crash (CRIT).
|
|
366
386
|
|
|
367
387
|
### 4. Did my change actually help?
|
|
368
388
|
|
|
@@ -439,6 +459,89 @@ Per-IP churn with first/last seen, plus an authenticated-users table showing
|
|
|
439
459
|
successful and failed logins per account and when each last authenticated —
|
|
440
460
|
the question that starts most access incidents.
|
|
441
461
|
|
|
462
|
+
### 7. Is this host running too many mongods for its memory?
|
|
463
|
+
|
|
464
|
+
```bash
|
|
465
|
+
mdbkit host /var/log/mongodb # every instance's log under here
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
```
|
|
469
|
+
== mdbkit host: 8 instance(s) on vm ==
|
|
470
|
+
last 1440 minutes of each log | 7.8 GiB RAM (this machine)
|
|
471
|
+
|
|
472
|
+
[CRIT] Cache sizes vs RAM: WiredTiger caches add up to 11.8 GiB, 150% of 7.8 GiB RAM (this machine).
|
|
473
|
+
[CRIT] Instances that crashed: 1 instance(s) started after an unclean stop (crash, kill -9 or OOM kill).
|
|
474
|
+
- vm:29021: 1 unclean start(s)
|
|
475
|
+
[WARN] Default cache size on a shared host: 3 of 8 mongod instances run with the default WiredTiger cache (cacheSizeGB not set). [...]
|
|
476
|
+
|
|
477
|
+
instance set version role cache starts crashes slow ops slow time waiting worst first issue
|
|
478
|
+
-------- ---- ------- ---------- ------- ------ ------- -------- --------- ------- ----- --------------------------
|
|
479
|
+
vm:29021 rs02 8.0.32 SECONDARY 256 MiB 2 1 0 - - CRIT Process start(s) in window
|
|
480
|
+
vm:29030 - 8.0.32 standalone 512 MiB 1 0 9 472ms 0% WARN Collection scans
|
|
481
|
+
vm:29010 rs01 8.0.32 PRIMARY 3.4 GiB 1 0 3 271ms 0% WARN Collection scans
|
|
482
|
+
[...]
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
For hosts that run many mongods side by side, typically one member of each
|
|
486
|
+
of many replica sets. The usual failure is that every instance was left on
|
|
487
|
+
the default WiredTiger cache, which assumes the machine is its alone; the
|
|
488
|
+
caches add up to several times the RAM and the OOM killer picks off
|
|
489
|
+
instances. (Output above is from a real 8-instance test host.)
|
|
490
|
+
|
|
491
|
+
### 8. Is my sharded cluster sending queries to every shard?
|
|
492
|
+
|
|
493
|
+
```bash
|
|
494
|
+
mdbkit queries /var/log/mongodb/mongos.log # how each query was routed
|
|
495
|
+
mdbkit triage /var/log/mongodb/mongos.log # scatter-gather, unreachable shards
|
|
496
|
+
mdbkit triage /var/log/mongodb/shard1.log # chunk migrations and why they failed
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
```
|
|
500
|
+
namespace op count cumMs mean max shards to all shard wait shape
|
|
501
|
+
shop.orders find 50 520ms 10ms 28ms 2 50/50 97% {createdAt:gt, status:eq} sort:{createdAt:-1}
|
|
502
|
+
shop.orders aggregate 20 291ms 14ms 20ms 2 20/20 90% {status:eq}
|
|
503
|
+
shop.orders find 80 19ms 0ms 3ms 1 0/80 21% {customerId:eq}
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
The router's log shows which query shapes went to every shard (usually no
|
|
507
|
+
shard key in the filter) and which went to one. The shards' logs show chunk
|
|
508
|
+
migrations, how much they moved and why any failed; the config server's
|
|
509
|
+
shows balancer errors. Plans live on the shards, so run `queries` and
|
|
510
|
+
`advise` on a shard log for index advice. (Output from a real 8.0 cluster,
|
|
511
|
+
sharded on `customerId`.)
|
|
512
|
+
|
|
513
|
+
### 9. Which indexes are not earning their keep?
|
|
514
|
+
|
|
515
|
+
```bash
|
|
516
|
+
mdbkit export-script indexes > export_indexes.js
|
|
517
|
+
mongosh --quiet "mongodb://your_db_host:27017/" --eval "$(cat export_indexes.js)" > indexes.json
|
|
518
|
+
mdbkit indexes indexes.json
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
```
|
|
522
|
+
exported from: a mongos (usage from each shard's primary)
|
|
523
|
+
|
|
524
|
+
Unused since the counters started (1)
|
|
525
|
+
shop.orders customerId_1_status_1 { customerId: 1, status: 1 } — 0 use(s)
|
|
526
|
+
no recorded use since the counters started
|
|
527
|
+
test safely: db.getSiblingDB("shop").getCollection("orders").hideIndex("customerId_1_status_1")
|
|
528
|
+
|
|
529
|
+
Redundant: a prefix of another index (1)
|
|
530
|
+
shop.orders status_1 { status: 1 } — 20 use(s)
|
|
531
|
+
its key is a prefix of status_1_createdAt_-1 { status: 1, createdAt: -1 }, which can serve the same queries
|
|
532
|
+
test safely: db.getSiblingDB("shop").getCollection("orders").hideIndex("status_1")
|
|
533
|
+
|
|
534
|
+
Unused, but not a candidate (1)
|
|
535
|
+
shop.orders createdAt_1 { createdAt: 1 } — 0 use(s)
|
|
536
|
+
unused for queries, but it is a TTL index: the TTL monitor uses it, which the counters do not show
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
Every index costs write time, memory and disk. This lists the ones with no
|
|
540
|
+
recorded use and the ones another index already covers, and explains the
|
|
541
|
+
ones it deliberately leaves alone (unique, TTL, hidden, the shard key's
|
|
542
|
+
index). It never says "drop": `hideIndex` is the reversible test. (Output
|
|
543
|
+
from a real 8.0 cluster, exported through mongos.)
|
|
544
|
+
|
|
442
545
|
---
|
|
443
546
|
|
|
444
547
|
## Running it on a schedule
|
|
@@ -513,6 +616,8 @@ mdbkit lab start # 3-node replica set on 127.0.0.1:28110-2811
|
|
|
513
616
|
mdbkit lab seed # 50k documents + a deliberately mixed workload
|
|
514
617
|
mdbkit queries $(mdbkit lab logs | head -1)
|
|
515
618
|
mdbkit lab destroy --yes # remove it entirely
|
|
619
|
+
|
|
620
|
+
mdbkit lab start --shards 2 # or a sharded cluster: config server, 2 shards, mongos
|
|
516
621
|
```
|
|
517
622
|
|
|
518
623
|
It binds to localhost only, uses ports far from 27017 so it can never be
|
|
@@ -545,8 +650,11 @@ cat mongod.log | mdbkit queries - # stdin
|
|
|
545
650
|
|
|
546
651
|
### `mdbkit loginfo <log>`
|
|
547
652
|
|
|
548
|
-
Overall log summary: server version,
|
|
549
|
-
|
|
653
|
+
Overall log summary: server version, what wrote the log (replica set
|
|
654
|
+
member, standalone, mongos, shard or config server, and its replica set),
|
|
655
|
+
host, restarts, connections accepted, slow-query count, still-running
|
|
656
|
+
operations (8.3+), chunk migrations (on a shard), warning/error counts, and a
|
|
657
|
+
per-component line breakdown.
|
|
550
658
|
|
|
551
659
|
| Option | Description |
|
|
552
660
|
|---|---|
|
|
@@ -591,6 +699,14 @@ included even though no index can speed up an insert: a slow insert is still
|
|
|
591
699
|
latency your application saw, and on 8.0+ the `--shape` view says whether it
|
|
592
700
|
was executing or waiting (on locks, flow control or write concern).
|
|
593
701
|
|
|
702
|
+
**On a mongos (router) log** the table changes: a router records how each
|
|
703
|
+
query was routed but not its plan (the shards have that), so `docsEx`,
|
|
704
|
+
`scan` and `plan` give way to `shards` (how many shards each execution went
|
|
705
|
+
to), `to all` (executions sent to every shard: scatter-gather) and
|
|
706
|
+
`shard wait` (the share of time spent waiting for the shards). Cluster
|
|
707
|
+
administration commands (`moveRange`, `shardCollection`, ...) are left out;
|
|
708
|
+
`triage` on the shard logs reports migrations.
|
|
709
|
+
|
|
594
710
|
```bash
|
|
595
711
|
mdbkit queries mongod.log
|
|
596
712
|
mdbkit queries mongod.log --sort scanRatio --limit 10
|
|
@@ -687,13 +803,14 @@ it chains with other tools (including mdbkit itself).
|
|
|
687
803
|
|
|
688
804
|
| Option | Description |
|
|
689
805
|
|---|---|
|
|
690
|
-
| `--component NAME` | `COMMAND`, `NETWORK`, `REPL`, `STORAGE`, `INDEX`, `WRITE`, `QUERY`, `CONTROL`, … |
|
|
806
|
+
| `--component NAME` | `COMMAND`, `NETWORK`, `REPL`, `ELECTION`, `STORAGE`, `INDEX`, `WRITE`, `QUERY`, `SHARDING`, `CONTROL`, … |
|
|
691
807
|
| `--severity S` | `I` info, `W` warning, `E` error, `F` fatal |
|
|
692
808
|
| `--ns NAMESPACE` | Exact namespace, e.g. `shop.orders` |
|
|
693
809
|
| `--slow N` | Only operations with `durationMillis` >= N |
|
|
694
810
|
| `--from TIMESTAMP` | Lower time bound (inclusive) |
|
|
695
811
|
| `--to TIMESTAMP` | Upper time bound (inclusive) |
|
|
696
812
|
| `--msg TEXT` | Substring match on the message field |
|
|
813
|
+
| `--failed` | Only operations that ended in an error (logged with an `errName`) |
|
|
697
814
|
| `--limit N` | Print only the **first** N matches |
|
|
698
815
|
| `--last N` | Print only the **last** N matches — usually what you want during an incident |
|
|
699
816
|
| `--as-explain` | Rebuild each matching slow query as a runnable `mongosh` `.explain()` command instead of printing the raw log line |
|
|
@@ -714,7 +831,7 @@ it chains with other tools (including mdbkit itself).
|
|
|
714
831
|
mdbkit filter mongod.log --severity E --last 20 # errors (most recent 20)
|
|
715
832
|
mdbkit filter mongod.log --severity F # fatal — always investigate
|
|
716
833
|
mdbkit filter mongod.log --severity W --last 50 # warnings
|
|
717
|
-
mdbkit filter mongod.log --component
|
|
834
|
+
mdbkit filter mongod.log --component ELECTION # elections and stepdowns
|
|
718
835
|
mdbkit filter mongod.log --slow 500 --ns shop.orders --limit 50
|
|
719
836
|
mdbkit filter mongod.log --from 2026-07-01T14:30:00+04:00 --to 2026-07-01T15:00:00+04:00
|
|
720
837
|
mdbkit filter mongod.log --slow 100 | mdbkit queries -
|
|
@@ -729,8 +846,8 @@ mdbkit filter mongod.log --ns shop.orders --slow 500 --last 3 --as-explain
|
|
|
729
846
|
|
|
730
847
|
# Or produce a runnable script, get the plan, and analyze it
|
|
731
848
|
mdbkit filter mongod.log --slow 500 --last 1 --as-explain --explain-script > q.js
|
|
732
|
-
mongosh --quiet --host your_db_host --username your_username
|
|
733
|
-
--password your_password --authenticationDatabase admin
|
|
849
|
+
mongosh --quiet --host your_db_host --username your_username \
|
|
850
|
+
--password your_password --authenticationDatabase admin \
|
|
734
851
|
--eval "$(cat q.js)" > explain.json
|
|
735
852
|
mdbkit explain explain.json
|
|
736
853
|
```
|
|
@@ -785,13 +902,13 @@ help — a candidate index from the same advisor engine.
|
|
|
785
902
|
|
|
786
903
|
```bash
|
|
787
904
|
# 1. Capture the plan (adjust host/credentials for your deployment)
|
|
788
|
-
mongosh --quiet
|
|
789
|
-
--host your_db_host
|
|
790
|
-
--port 27017
|
|
791
|
-
--username your_username
|
|
792
|
-
--password your_password
|
|
793
|
-
--authenticationDatabase admin
|
|
794
|
-
--eval 'EJSON.stringify(db.getSiblingDB("shop").orders.find({status:"open"}).sort({ts:-1}).explain("executionStats"))'
|
|
905
|
+
mongosh --quiet \
|
|
906
|
+
--host your_db_host \
|
|
907
|
+
--port 27017 \
|
|
908
|
+
--username your_username \
|
|
909
|
+
--password your_password \
|
|
910
|
+
--authenticationDatabase admin \
|
|
911
|
+
--eval 'EJSON.stringify(db.getSiblingDB("shop").orders.find({status:"open"}).sort({ts:-1}).explain("executionStats"))' \
|
|
795
912
|
> explain.json
|
|
796
913
|
|
|
797
914
|
# 2. Analyze it
|
|
@@ -822,7 +939,10 @@ one screen that says what happened, how bad it is, and where to look next.
|
|
|
822
939
|
| `--window N` | 60 | Analyze the last N minutes of log time; `0` = the whole file |
|
|
823
940
|
| `--dbpath PATH` | auto | Override the data directory used for the disk check |
|
|
824
941
|
| `--no-sysprobe` | off | Skip local disk/memory/CPU probes — use when analyzing a log copied off the host |
|
|
825
|
-
| `--ftdc PATH` | | `diagnostic.data` directory — adds CPU, memory, cache,
|
|
942
|
+
| `--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) |
|
|
943
|
+
| `--oslog FILE...` | | System log(s): OOM kills, file-descriptor limits and I/O errors that the mongod log cannot record |
|
|
944
|
+
| `--only LEVELS` | | Show only these severities, e.g. `--only CRIT,WARN` |
|
|
945
|
+
| `--exit-code` | | Exit 2 on CRIT, 1 on WARN, else 0 |
|
|
826
946
|
| `--report FILE` | | Write a shareable `.md` or `.html` report instead of terminal output |
|
|
827
947
|
| `--json` | | Machine-readable output |
|
|
828
948
|
|
|
@@ -838,24 +958,95 @@ mdbkit triage mongod.log --window 0 --no-sysprobe
|
|
|
838
958
|
with no clean shutdown before it is a CRIT, because that is what a crash,
|
|
839
959
|
`kill -9` or OOM kill looks like. mongod itself records whether its previous
|
|
840
960
|
shutdown was clean, so mdbkit can tell even when the crash happened before
|
|
841
|
-
the log you are reading begins.
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
961
|
+
the log you are reading begins.
|
|
962
|
+
|
|
963
|
+
**Elections.** An election because a member saw no primary is a CRIT: the
|
|
964
|
+
primary was lost (crash, kill, hang or network). A stepdown command ("step
|
|
965
|
+
up request") or a higher-priority member taking over is a WARN, worded as
|
|
966
|
+
probably deliberate. The first election of a newly initiated replica set is
|
|
967
|
+
INFO, not instability.
|
|
968
|
+
|
|
969
|
+
**Flow control, cache pressure and checkpoints.** Flow control is read from
|
|
970
|
+
the log (MongoDB warns every 10 seconds while it throttles writes) and from
|
|
971
|
+
FTDC (how long it was engaged and how long writers waited). Cache pressure
|
|
972
|
+
comes from FTDC: how long the cache sat past the points where application
|
|
973
|
+
threads must help evict (95% full or 20% dirty), and how much time they
|
|
974
|
+
spent evicting in the busiest minute. A slow checkpoint is a WARN past 60
|
|
975
|
+
seconds; FTDC records every checkpoint's duration, and MongoDB 8.3+ also
|
|
976
|
+
logs one that runs past 20 seconds. Each of these was checked on real 6.0,
|
|
977
|
+
7.0, 8.0 and 9.0 servers driven into that state.
|
|
978
|
+
|
|
979
|
+
**Sharded clusters.** On a mongos log, `triage` reports queries sent to every
|
|
980
|
+
shard (scatter-gather), time spent waiting on the shards, routing-table
|
|
981
|
+
refreshes, and shards or members the router could not reach. On a shard's
|
|
982
|
+
log it reports chunk migrations (how many, how much data, and why any
|
|
983
|
+
failed, e.g. waiting for the range deleter); on the config server's,
|
|
984
|
+
balancer errors. On any log, **failed operations** on your collections (a
|
|
985
|
+
query or write that ended in an error such as
|
|
986
|
+
`FailedToSatisfyReadPreference` or `MaxTimeMSExpired`) are grouped by
|
|
987
|
+
error; `mdbkit filter <log> --failed` prints them.
|
|
988
|
+
|
|
989
|
+
**Hosts running several mongods.** `triage` reads one instance's log; don't
|
|
990
|
+
pass several instances' logs to it, because several files are read as one
|
|
991
|
+
stream (that is for the rotated logs of one instance, or the members of one
|
|
992
|
+
replica set). For the whole host at once, use [`mdbkit host`](#mdbkit-host-logs).
|
|
993
|
+
When several mongods run on the host, `triage` uses the pid and dbPath the
|
|
994
|
+
log records (in its startup line, or at the top of a rotated file) to pick
|
|
849
995
|
the right process for its memory, uptime and disk checks, and when
|
|
850
996
|
`--oslog` shows an OOM kill it says whether the killed pid was this
|
|
851
997
|
instance or another one.
|
|
852
998
|
|
|
999
|
+
---
|
|
1000
|
+
|
|
1001
|
+
### `mdbkit host <logs...>`
|
|
1002
|
+
|
|
1003
|
+
One host running many mongod instances: one line per instance, and checks
|
|
1004
|
+
that only make sense for the host as a whole.
|
|
1005
|
+
|
|
1006
|
+
| Option | Default | Description |
|
|
1007
|
+
|---|---|---|
|
|
1008
|
+
| `--window N` | 1440 | Analyze the last N minutes of each log; `0` = whole logs |
|
|
1009
|
+
| `--ram SIZE` | | The host's memory (`64G`, `65536M`) when the logs were copied off it. On the host it is read from `/proc` |
|
|
1010
|
+
| `--oslog FILE...` | | System log(s): each OOM kill is matched to the instance it killed |
|
|
1011
|
+
| `--limit N` | all | Show only the N worst instances |
|
|
1012
|
+
| `--exit-code` | | Exit 2 on CRIT, 1 on WARN, else 0 |
|
|
1013
|
+
| `--json` | | Machine-readable output |
|
|
1014
|
+
|
|
853
1015
|
```bash
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1016
|
+
mdbkit host /var/log/mongodb # finds every *.log* below
|
|
1017
|
+
mdbkit host /var/log/mongodb --oslog /var/log/syslog # who did the OOM killer hit?
|
|
1018
|
+
mdbkit host "/mnt/copied/db7/*/mongod.log*" --ram 256G --limit 15
|
|
1019
|
+
```
|
|
1020
|
+
|
|
1021
|
+
Give it files, globs or directories (searched three levels deep, never into
|
|
1022
|
+
a data directory). Files are grouped into instances by the host and port the
|
|
1023
|
+
log records, so rotated files join their instance even though they have no
|
|
1024
|
+
startup line.
|
|
1025
|
+
|
|
1026
|
+
**Per instance:** replica set, version, role, WiredTiger cache size, starts
|
|
1027
|
+
and crashes (unclean stops), slow operations and their total time, the share
|
|
1028
|
+
of that time spent waiting (8.0+), and its worst finding from the same
|
|
1029
|
+
detectors `triage` uses. Shard and config server members are labelled as
|
|
1030
|
+
such, and a mongos on the same host gets a line of its own (it has no cache,
|
|
1031
|
+
so it is left out of the cache total).
|
|
1032
|
+
|
|
1033
|
+
**For the host:**
|
|
1034
|
+
|
|
1035
|
+
- **Cache sizes vs RAM.** Each instance's cache comes from its own log
|
|
1036
|
+
("Opening WiredTiger" states the size, even when it is the default). The
|
|
1037
|
+
total is compared with the RAM: WARN above 60%, CRIT above 85%. These are
|
|
1038
|
+
rules of thumb: MongoDB's single-instance default is about half the RAM,
|
|
1039
|
+
leaving the rest to the OS file cache and each process's connections,
|
|
1040
|
+
sorts and aggregations.
|
|
1041
|
+
- **Default cache on a shared host.** Instances without `cacheSizeGB` each
|
|
1042
|
+
assume the whole machine is theirs.
|
|
1043
|
+
- **Crashes** across all instances, and with `--oslog`, every OOM kill
|
|
1044
|
+
matched to the instance it hit by pid.
|
|
1045
|
+
- **Startup warnings counted across instances.** Kernel and limit settings
|
|
1046
|
+
belong to the host, so "Open-file limit is too low: 54 of 54 instances" is
|
|
1047
|
+
one fix, not 54.
|
|
1048
|
+
- **On the host itself:** instances with a log but no running mongod, and
|
|
1049
|
+
running mongods whose logs were not given.
|
|
859
1050
|
|
|
860
1051
|
---
|
|
861
1052
|
|
|
@@ -910,7 +1101,7 @@ not encrypted; mdbkit decodes it offline.
|
|
|
910
1101
|
| `--all` | off | Analyze the entire history (see the performance note below) |
|
|
911
1102
|
| `--metric LABEL` | all | Restrict to one metric (repeatable), e.g. `--metric conns.current` |
|
|
912
1103
|
| `--step SECONDS` | 60 | Timeline bucket size |
|
|
913
|
-
| `--from` / `--to` | | Explicit time bounds (same formats as `filter`) |
|
|
1104
|
+
| `--from` / `--to` | | Explicit time bounds, UTC unless the value has an offset (same formats as `filter`) |
|
|
914
1105
|
| `--json` | | Machine-readable output |
|
|
915
1106
|
|
|
916
1107
|
**Performance note.** `diagnostic.data` can hold weeks of per-second samples —
|
|
@@ -929,12 +1120,18 @@ mdbkit ftdc export diagnostic.data > metrics.csv
|
|
|
929
1120
|
|
|
930
1121
|
In `timeline`, gauges (connections, cache bytes, tickets) show the peak in
|
|
931
1122
|
each bucket and cumulative counters (`ops.*`, `sys.cpu.*`) show their rate
|
|
932
|
-
per second over it.
|
|
1123
|
+
per second over it. FTDC records time in UTC, and these commands show it as
|
|
1124
|
+
UTC; `triage --ftdc` converts it to the log's own time zone so the two line
|
|
1125
|
+
up.
|
|
933
1126
|
|
|
934
1127
|
Metric labels include `ops.*` (insert/query/update/delete/getmore/command),
|
|
935
1128
|
`conns.current`, `conns.available`, `queue.readers`, `queue.writers`,
|
|
936
1129
|
`cache.usedBytes`, `cache.maxBytes`, `cache.dirtyBytes`, `tickets.*`,
|
|
937
|
-
`
|
|
1130
|
+
`checkpoint.lastMs`, `evict.appThreadMicros`, `flowControl.*`,
|
|
1131
|
+
`mem.residentMB`, and on Linux `sys.cpu.*` and `sys.mem.availableKB`. The
|
|
1132
|
+
same labels work across versions where MongoDB renamed the underlying
|
|
1133
|
+
statistic (checked on 6.0 to 9.0), and on 8.0+ shard servers and mongos,
|
|
1134
|
+
which group their metrics by role.
|
|
938
1135
|
|
|
939
1136
|
The data directory can be copied off the host and analyzed elsewhere — it
|
|
940
1137
|
contains metrics only, never document contents.
|
|
@@ -959,16 +1156,17 @@ Markdown output looks like this:
|
|
|
959
1156
|
```markdown
|
|
960
1157
|
# MongoDB incident triage
|
|
961
1158
|
|
|
962
|
-
*window 2026-07-01 08:
|
|
1159
|
+
*window 2026-07-01 08:29 -> 09:29 · generated 2026-07-01 09:31*
|
|
963
1160
|
|
|
964
1161
|
## Findings
|
|
965
1162
|
|
|
966
|
-
- **[CRIT] Replica set instability** —
|
|
967
|
-
- Starting an election, since we've seen no PRIMARY in election timeout period
|
|
968
|
-
-
|
|
969
|
-
-
|
|
970
|
-
|
|
971
|
-
-
|
|
1163
|
+
- **[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.
|
|
1164
|
+
- 08:50:32 Starting an election, since we've seen no PRIMARY in election timeout period
|
|
1165
|
+
- 08:50:34 Election succeeded, assuming primary role
|
|
1166
|
+
- *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.`
|
|
1167
|
+
- **[WARN] Connection storm** — 1 minute(s) at >= 60 new connections/min (baseline median 0/min); peak 220 at 08:49.
|
|
1168
|
+
- 10.20.9.77: 220 in the peak minute
|
|
1169
|
+
- *next:* `Identify the client: mdbkit connections <log> — look for pool misconfiguration or crash-loop reconnects.`
|
|
972
1170
|
- **[OK] Errors** — No error/fatal severity lines in window.
|
|
973
1171
|
```
|
|
974
1172
|
|
|
@@ -1017,12 +1215,12 @@ or rehearsing a demo. This is the only command that starts external
|
|
|
1017
1215
|
processes; see [SECURITY.md](SECURITY.md) for exactly how it is bounded.
|
|
1018
1216
|
|
|
1019
1217
|
Requires `mongod` on your `PATH` (and `mongosh` to initiate the replica set
|
|
1020
|
-
and seed data). Linux and macOS.
|
|
1218
|
+
and seed data; a sharded lab also needs `mongos`). Linux and macOS.
|
|
1021
1219
|
|
|
1022
1220
|
| Action | What it does |
|
|
1023
1221
|
|---|---|
|
|
1024
|
-
| `start` | Create and start a replica set, print the connection string and log paths |
|
|
1025
|
-
| `seed` | Insert sample data and run a workload with deliberately interesting queries |
|
|
1222
|
+
| `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) |
|
|
1223
|
+
| `seed` | Insert sample data and run a workload with deliberately interesting queries (`--workload-only`: just the queries, on the data already there) |
|
|
1026
1224
|
| `status` | Show ports, pids and whether each node is running |
|
|
1027
1225
|
| `logs` | Print the log file paths, ready to pipe into other commands |
|
|
1028
1226
|
| `stop` | Stop the nodes, keep the data |
|
|
@@ -1031,11 +1229,13 @@ and seed data). Linux and macOS.
|
|
|
1031
1229
|
| Option | Default | Description |
|
|
1032
1230
|
|---|---|---|
|
|
1033
1231
|
| `--dir PATH` | `~/.mdbkit-lab` | Where the lab lives |
|
|
1034
|
-
| `--nodes N` | 3 | Replica set size |
|
|
1232
|
+
| `--nodes N` | 3 | Replica set size (with `--shards`: each shard's replica set, default 1) |
|
|
1233
|
+
| `--shards N` | | A sharded cluster with N shards, a config server and a mongos |
|
|
1035
1234
|
| `--port N` | 28110 | Base port — deliberately far from 27017 |
|
|
1036
1235
|
| `--slowms N` | 0 | Log every operation, which is what makes the log worth reading |
|
|
1037
1236
|
| `--standalone` | off | Single node, no replica set |
|
|
1038
1237
|
| `--docs N` | 50000 | Documents inserted by `seed` |
|
|
1238
|
+
| `--workload-only` | | `seed` runs the queries again on the data already there |
|
|
1039
1239
|
| `--yes` | | Confirm `destroy` |
|
|
1040
1240
|
|
|
1041
1241
|
**The full loop:**
|
|
@@ -1059,11 +1259,25 @@ mdbkit lab logs
|
|
|
1059
1259
|
# /home/you/.mdbkit-lab/node1/mongod.log
|
|
1060
1260
|
# /home/you/.mdbkit-lab/node2/mongod.log
|
|
1061
1261
|
|
|
1062
|
-
mdbkit queries $(mdbkit lab logs | head -1) #
|
|
1262
|
+
mdbkit queries $(mdbkit lab logs | head -1) # node0, the preferred primary
|
|
1063
1263
|
mdbkit triage $(mdbkit lab logs) # all three as one stream
|
|
1064
1264
|
mdbkit loginfo $(mdbkit lab logs | sed -n 2p) # a specific secondary
|
|
1065
1265
|
```
|
|
1066
1266
|
|
|
1267
|
+
**A sharded cluster**: a config server, N single-node shards (`--nodes 3`
|
|
1268
|
+
makes each shard a three-node replica set) and a mongos. `seed` shards
|
|
1269
|
+
`shop.orders` on `customerId`, moves a range to every shard, then runs
|
|
1270
|
+
targeted and scatter-gather queries through mongos. `logs` lists the mongos
|
|
1271
|
+
log first:
|
|
1272
|
+
|
|
1273
|
+
```bash
|
|
1274
|
+
mdbkit lab start --shards 2 # config 28110, shards 28111-28112, mongos 28113
|
|
1275
|
+
mdbkit lab seed
|
|
1276
|
+
mdbkit queries $(mdbkit lab logs | head -1) # the router: shards per query
|
|
1277
|
+
mdbkit triage $(mdbkit lab logs | sed -n 3p) # a shard: migrations, its queries
|
|
1278
|
+
mdbkit lab destroy --yes
|
|
1279
|
+
```
|
|
1280
|
+
|
|
1067
1281
|
**A single node**, when you do not need replication. It starts faster, and
|
|
1068
1282
|
`start` works without `mongosh` (`seed` still needs it):
|
|
1069
1283
|
|
|
@@ -1094,22 +1308,39 @@ mdbkit lab start # back up with the same data
|
|
|
1094
1308
|
mdbkit lab status # ports, pids, running or not
|
|
1095
1309
|
```
|
|
1096
1310
|
|
|
1311
|
+
**Rehearse a failure.** Kill a node the way a crash or the OOM killer would,
|
|
1312
|
+
see what mdbkit makes of it, then bring it back. `start` on an existing lab
|
|
1313
|
+
starts only the nodes that are down, on their old ports:
|
|
1314
|
+
|
|
1315
|
+
```bash
|
|
1316
|
+
kill -9 $(cat ~/.mdbkit-lab/node0/mongod.pid) # the primary dies
|
|
1317
|
+
sleep 20 # the others elect a new one
|
|
1318
|
+
mdbkit lab start # node0 comes back
|
|
1319
|
+
mdbkit triage $(mdbkit lab logs) --window 0 # crash, failover, recovery
|
|
1320
|
+
```
|
|
1321
|
+
|
|
1097
1322
|
**A complete before/after experiment**, which is what `lab` is really for:
|
|
1098
1323
|
|
|
1099
1324
|
```bash
|
|
1100
1325
|
mdbkit lab start && mdbkit lab seed
|
|
1101
1326
|
cp $(mdbkit lab logs | head -1) before.log
|
|
1327
|
+
mongosh --port 28110 --quiet --eval 'db.adminCommand({logRotate: 1})' # start a fresh log
|
|
1102
1328
|
|
|
1103
1329
|
mongosh --port 28110 --eval \
|
|
1104
1330
|
'db.getSiblingDB("shop").orders.createIndex({status:1, createdAt:-1})'
|
|
1105
1331
|
|
|
1106
|
-
mdbkit lab seed
|
|
1332
|
+
mdbkit lab seed --workload-only # the same queries, now with the index
|
|
1107
1333
|
cp $(mdbkit lab logs | head -1) after.log
|
|
1108
1334
|
|
|
1109
1335
|
mdbkit compare before.log --after after.log
|
|
1110
1336
|
mdbkit lab destroy --yes
|
|
1111
1337
|
```
|
|
1112
1338
|
|
|
1339
|
+
`--workload-only` runs the queries again without reloading the data, so the
|
|
1340
|
+
index you added stays; a plain `seed` reloads and would drop it. Rotating the
|
|
1341
|
+
log keeps the second run's lines apart from the first's, because lab logs
|
|
1342
|
+
are appended to across restarts.
|
|
1343
|
+
|
|
1113
1344
|
`seed` runs indexed point lookups alongside deliberately unindexed queries —
|
|
1114
1345
|
an equality-plus-range-plus-sort with no supporting index, an aggregation
|
|
1115
1346
|
that scans the collection, and updates whose predicate has no index — so the
|
|
@@ -1118,8 +1349,9 @@ log immediately contains something worth analysing.
|
|
|
1118
1349
|
**Safety.** The lab binds to `127.0.0.1` only, refuses to use or delete any
|
|
1119
1350
|
directory it did not create, and never touches a MongoDB it did not start.
|
|
1120
1351
|
Before it signals a process it checks that the pid still belongs to one of
|
|
1121
|
-
its own `mongod`s
|
|
1122
|
-
stale pid file can never kill something
|
|
1352
|
+
its own `mongod`s or its `mongos` (the command line names the lab's data
|
|
1353
|
+
directory or log file), so a stale pid file can never kill something
|
|
1354
|
+
unrelated. `destroy` refuses to
|
|
1123
1355
|
delete data while a lab node is still running. If a port is already taken it
|
|
1124
1356
|
says so before starting anything. If a start fails halfway, the lab is left
|
|
1125
1357
|
in a state `mdbkit lab destroy --yes` can clean up, and the error says so.
|
|
@@ -1258,19 +1490,59 @@ duration moving by more than 20%.
|
|
|
1258
1490
|
|
|
1259
1491
|
---
|
|
1260
1492
|
|
|
1261
|
-
### `mdbkit
|
|
1493
|
+
### `mdbkit indexes <file>...`
|
|
1494
|
+
|
|
1495
|
+
Unused and redundant indexes, from what `mdbkit export-script indexes`
|
|
1496
|
+
exported (index definitions plus `$indexStats` usage counters).
|
|
1497
|
+
|
|
1498
|
+
| Option | Default | Description |
|
|
1499
|
+
|---|---|---|
|
|
1500
|
+
| `--ns NAMESPACE` | all | Only this collection |
|
|
1501
|
+
| `--min-days N` | 7 | Warn when the usage counters cover fewer days than this |
|
|
1502
|
+
| `--exit-code` | | Exit 1 when there is an unused or redundant index |
|
|
1503
|
+
| `--json` | | Machine-readable output |
|
|
1504
|
+
|
|
1505
|
+
```bash
|
|
1506
|
+
mdbkit indexes indexes.json
|
|
1507
|
+
mdbkit indexes primary.json secondary1.json secondary2.json # combine members
|
|
1508
|
+
mdbkit indexes indexes.json --ns shop.orders
|
|
1509
|
+
```
|
|
1510
|
+
|
|
1511
|
+
What it reports:
|
|
1512
|
+
|
|
1513
|
+
- **Unused:** no recorded use since the counters started.
|
|
1514
|
+
- **Redundant:** its key is a prefix of another index with the same
|
|
1515
|
+
collation, which can serve the same queries (`{a: 1}` when `{a: 1, b: 1}`
|
|
1516
|
+
exists). Partial, sparse and special (text, 2dsphere, hashed, wildcard)
|
|
1517
|
+
indexes are never treated as covering or covered.
|
|
1518
|
+
- **Not candidates:** `_id`, unique indexes (they enforce a constraint),
|
|
1519
|
+
TTL indexes (the TTL monitor's deletes do not count as use, checked on
|
|
1520
|
+
8.0 and 9.0), hidden indexes, and the index the shard key needs.
|
|
1521
|
+
|
|
1522
|
+
Usage counters are kept **per member** and **reset when a member restarts**.
|
|
1523
|
+
An index unused on the primary may serve reads on a secondary, and one used
|
|
1524
|
+
monthly can look unused after a week. So export from every member (or
|
|
1525
|
+
through mongos for a sharded cluster) and pass all the files, and check the
|
|
1526
|
+
counter window mdbkit prints. It never recommends dropping anything: it
|
|
1527
|
+
prints the `hideIndex` command, which makes the planner ignore the index
|
|
1528
|
+
while it is still maintained, so `unhideIndex` undoes it instantly.
|
|
1529
|
+
|
|
1530
|
+
---
|
|
1531
|
+
|
|
1532
|
+
### `mdbkit export-script {schema|indexes|serverstatus}`
|
|
1262
1533
|
|
|
1263
1534
|
Prints a small `mongosh` script to stdout. **mdbkit never connects to your
|
|
1264
1535
|
database**. You run these yourself, so you can read exactly what they do
|
|
1265
|
-
first.
|
|
1536
|
+
first. All are read-only. `schema` exports **field names and types only,
|
|
1266
1537
|
never document values**. `indexes` exports the index definitions from
|
|
1267
|
-
`getIndexes()
|
|
1268
|
-
values
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1538
|
+
`getIndexes()` (a partial index's filter expression can contain literal
|
|
1539
|
+
values) and, where your role allows `$indexStats`, how often each index has
|
|
1540
|
+
been used; through mongos it also records the shard keys.
|
|
1541
|
+
|
|
1542
|
+
`schema` and `indexes` cover **every database you can read** (`admin`,
|
|
1543
|
+
`config` and `local` skipped) and key collections by full namespace, so it
|
|
1544
|
+
does not matter which database mongosh connects to. To export one database
|
|
1545
|
+
only, set `ONLY_DB` at the top of the script. They write relaxed Extended
|
|
1274
1546
|
JSON, so 64-bit counters come out as plain numbers.
|
|
1275
1547
|
|
|
1276
1548
|
```bash
|
|
@@ -1286,40 +1558,42 @@ mdbkit export-script serverstatus > export_serverstatus.js
|
|
|
1286
1558
|
Terminal output is and will remain first-class — this tool is built for the
|
|
1287
1559
|
Linux box the database actually runs on.
|
|
1288
1560
|
|
|
1289
|
-
**
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
**Shipped in v0.
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1561
|
+
**v0.8 is a long-term release.** Nothing further is scheduled. Bug reports
|
|
1562
|
+
are still read, and misread log lines are still the most useful thing to
|
|
1563
|
+
send.
|
|
1564
|
+
|
|
1565
|
+
**Shipped in v0.8:**
|
|
1566
|
+
|
|
1567
|
+
* **Sharded clusters.** mongos logs show how many shards each query shape
|
|
1568
|
+
went to, which ones went to all of them, and the time spent waiting on
|
|
1569
|
+
shards and refreshing routing tables. Shard and config server logs show
|
|
1570
|
+
chunk migrations (with the reason when one fails), the range deleter, the
|
|
1571
|
+
balancer's errors, unreachable shards and failed application operations.
|
|
1572
|
+
FTDC from 8.0+ shard servers and mongos decodes. `mdbkit lab --shards N`
|
|
1573
|
+
builds a cluster to try it on.
|
|
1574
|
+
* **`mdbkit indexes`:** unused and redundant indexes from `$indexStats`,
|
|
1575
|
+
across replica set members or shards, with the reversible `hideIndex`
|
|
1576
|
+
command rather than a drop.
|
|
1577
|
+
* **The beta detectors checked against real failures.** Elections and
|
|
1578
|
+
stepdowns, flow control, cache pressure and slow checkpoints were
|
|
1579
|
+
reproduced on real MongoDB 6.0, 7.0, 8.0 and 9.0 servers (a killed
|
|
1580
|
+
primary, a stepdown, a connection storm, frozen secondaries, a small
|
|
1581
|
+
cache under load, a checkpoint held up for a minute), so none is labelled
|
|
1582
|
+
beta any more. That turned up real bugs, now fixed: flow control was never
|
|
1583
|
+
spotted in the log, a failover soon after a set was created was taken for
|
|
1584
|
+
its set-up, a stepdown was invisible on the primary that stepped down, and
|
|
1585
|
+
every chunk migration looked like a shutdown on the receiving shard.
|
|
1586
|
+
* `filter --failed`, `lab start` restarting only the nodes that are down,
|
|
1587
|
+
`lab seed --workload-only`, and FTDC checkpoint and eviction metrics under
|
|
1588
|
+
their 8.0 names.
|
|
1589
|
+
|
|
1590
|
+
**Shipped before:** v0.7's `host` (hosts running many mongods); v0.6.1's
|
|
1591
|
+
testing against real servers; v0.6's 8.x/9.0 log fields and `audit`; v0.5's
|
|
1592
|
+
`oslog` and `serverstatus`; v0.4's `compare`; v0.3's `demo` and `lab`; v0.2's
|
|
1593
|
+
FTDC decoding, incident triage and shareable reports.
|
|
1594
|
+
|
|
1595
|
+
**Ideas, not scheduled:** jumbo chunks and balancer windows; slow oplog
|
|
1596
|
+
application on secondaries; `lab` on Windows.
|
|
1323
1597
|
|
|
1324
1598
|
## Bugs, feature requests, questions
|
|
1325
1599
|
|