mdbkit 0.1.1__tar.gz → 0.2.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.1.1/mdbkit.egg-info → mdbkit-0.2.0}/PKG-INFO +108 -17
- mdbkit-0.1.1/PKG-INFO → mdbkit-0.2.0/README.md +553 -486
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/__init__.py +1 -1
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/advisor.py +10 -1
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/cli.py +122 -3
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/explain.py +46 -9
- mdbkit-0.2.0/mdbkit/ftdc.py +466 -0
- mdbkit-0.2.0/mdbkit/rebuild.py +171 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/render.py +108 -0
- mdbkit-0.2.0/mdbkit/report.py +187 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/triage.py +103 -4
- mdbkit-0.1.1/README.md → mdbkit-0.2.0/mdbkit.egg-info/PKG-INFO +577 -462
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit.egg-info/SOURCES.txt +5 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/pyproject.toml +1 -1
- {mdbkit-0.1.1 → mdbkit-0.2.0}/tests/test_explain.py +30 -2
- mdbkit-0.2.0/tests/test_ftdc.py +266 -0
- mdbkit-0.2.0/tests/test_rebuild_report.py +125 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/LICENSE +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/analysis.py +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/filtering.py +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/parser.py +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit/scripts.py +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit.egg-info/dependency_links.txt +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit.egg-info/entry_points.txt +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit.egg-info/requires.txt +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/mdbkit.egg-info/top_level.txt +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/setup.cfg +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/tests/test_mdbkit.py +0 -0
- {mdbkit-0.1.1 → mdbkit-0.2.0}/tests/test_triage.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mdbkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Offline toolkit for MongoDB 4.4+ structured logs: log analysis, slow-query shapes, connection churn, and deterministic index advice. A spiritual successor to mtools' log tools.
|
|
5
5
|
Author: Saqib Ameen Subhan
|
|
6
6
|
License: MIT
|
|
@@ -137,18 +137,18 @@ mongosh --quiet "mongodb://localhost/yourdb" export_schema.js > schema.json
|
|
|
137
137
|
|
|
138
138
|
# With authentication (typical production setup):
|
|
139
139
|
mongosh --quiet \
|
|
140
|
-
--host
|
|
140
|
+
--host your_db_host \
|
|
141
141
|
--port 27017 \
|
|
142
|
-
--username
|
|
143
|
-
--password
|
|
142
|
+
--username your_username \
|
|
143
|
+
--password your_password \
|
|
144
144
|
--authenticationDatabase admin \
|
|
145
145
|
--eval "$(cat export_indexes.js)" > indexes.json
|
|
146
146
|
|
|
147
147
|
mongosh --quiet \
|
|
148
|
-
--host
|
|
148
|
+
--host your_db_host \
|
|
149
149
|
--port 27017 \
|
|
150
|
-
--username
|
|
151
|
-
--password
|
|
150
|
+
--username your_username \
|
|
151
|
+
--password your_password \
|
|
152
152
|
--authenticationDatabase admin \
|
|
153
153
|
--eval "$(cat export_schema.js)" > schema.json
|
|
154
154
|
```
|
|
@@ -295,6 +295,7 @@ query with different parameters is counted once.
|
|
|
295
295
|
| `--limit N` | all | Show only the top N shapes |
|
|
296
296
|
| `--min-ms N` | 0 | Ignore operations faster than N milliseconds |
|
|
297
297
|
| `--include-system` | off | Include internal `admin`/`config`/`local` namespaces (hidden by default — they are server housekeeping, not your workload) |
|
|
298
|
+
| `--report FILE` | | Write a shareable `.md` or `.html` report instead |
|
|
298
299
|
| `--json` | | Machine-readable output |
|
|
299
300
|
|
|
300
301
|
**Reading the columns:**
|
|
@@ -343,6 +344,8 @@ it chains with other tools (including mdbkit itself).
|
|
|
343
344
|
| `--msg TEXT` | Substring match on the message field |
|
|
344
345
|
| `--limit N` | Print only the **first** N matches |
|
|
345
346
|
| `--last N` | Print only the **last** N matches — usually what you want during an incident |
|
|
347
|
+
| `--as-explain` | Rebuild each matching slow query as a runnable `mongosh` `.explain()` command instead of printing the raw log line |
|
|
348
|
+
| `--explain-script` | With `--as-explain`, wrap in `EJSON.stringify()` plus usage comments so it can be saved as a `.js` file |
|
|
346
349
|
|
|
347
350
|
**Timestamp formats accepted** by `--from` / `--to`:
|
|
348
351
|
|
|
@@ -356,13 +359,33 @@ it chains with other tools (including mdbkit itself).
|
|
|
356
359
|
```
|
|
357
360
|
|
|
358
361
|
```bash
|
|
359
|
-
mdbkit filter mongod.log --severity E --last 20
|
|
362
|
+
mdbkit filter mongod.log --severity E --last 20 # errors (most recent 20)
|
|
363
|
+
mdbkit filter mongod.log --severity F # fatal — always investigate
|
|
364
|
+
mdbkit filter mongod.log --severity W --last 50 # warnings
|
|
360
365
|
mdbkit filter mongod.log --component REPL --msg election
|
|
361
366
|
mdbkit filter mongod.log --slow 500 --ns shop.orders --limit 50
|
|
362
367
|
mdbkit filter mongod.log --from 2026-07-01T14:30:00+04:00 --to 2026-07-01T15:00:00+04:00
|
|
363
368
|
mdbkit filter mongod.log --slow 100 | mdbkit queries -
|
|
364
369
|
```
|
|
365
370
|
|
|
371
|
+
**From a slow query in the log to an explain plan**, without hand-writing the
|
|
372
|
+
query — `--as-explain` rebuilds the command that ran:
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
# See the actual commands behind your slowest operations
|
|
376
|
+
mdbkit filter mongod.log --ns shop.orders --slow 500 --last 3 --as-explain
|
|
377
|
+
|
|
378
|
+
# Or produce a runnable script, get the plan, and analyze it
|
|
379
|
+
mdbkit filter mongod.log --slow 500 --last 1 --as-explain --explain-script > q.js
|
|
380
|
+
mongosh --quiet --host your_db_host --username your_username \\
|
|
381
|
+
--password your_password --authenticationDatabase admin \\
|
|
382
|
+
--eval "$(cat q.js)" > explain.json
|
|
383
|
+
mdbkit explain explain.json
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
> Rebuilt commands contain the **real values** from your log (not redacted
|
|
387
|
+
> shapes) — treat them as sensitive.
|
|
388
|
+
|
|
366
389
|
---
|
|
367
390
|
|
|
368
391
|
### `mdbkit advise <log>`
|
|
@@ -406,33 +429,98 @@ help — a candidate index from the same advisor engine.
|
|
|
406
429
|
| `--schema FILE` | Field-type caveats |
|
|
407
430
|
| `--json` | Machine-readable output |
|
|
408
431
|
|
|
409
|
-
|
|
432
|
+
**Full example.** Get a plan for a query and analyze it:
|
|
433
|
+
|
|
410
434
|
```bash
|
|
411
|
-
|
|
435
|
+
# 1. Capture the plan (adjust host/credentials for your deployment)
|
|
436
|
+
mongosh --quiet \\
|
|
437
|
+
--host your_db_host \\
|
|
438
|
+
--port 27017 \\
|
|
439
|
+
--username your_username \\
|
|
440
|
+
--password your_password \\
|
|
441
|
+
--authenticationDatabase admin \\
|
|
442
|
+
--eval 'EJSON.stringify(db.getSiblingDB("shop").orders.find({status:"open"}).sort({ts:-1}).explain("executionStats"))' \\
|
|
443
|
+
> explain.json
|
|
444
|
+
|
|
445
|
+
# 2. Analyze it
|
|
412
446
|
mdbkit explain explain.json
|
|
447
|
+
|
|
448
|
+
# 3. Sharper, with your existing indexes and sampled schema
|
|
449
|
+
mdbkit explain explain.json --indexes indexes.json --schema schema.json
|
|
413
450
|
```
|
|
414
451
|
|
|
452
|
+
Don't want to write the query by hand? `mdbkit filter ... --as-explain`
|
|
453
|
+
rebuilds it from the log for you (see the `filter` section above).
|
|
454
|
+
|
|
455
|
+
Legacy `mongo` shell and Compass output containing `NumberLong(...)`,
|
|
456
|
+
`ISODate(...)` or `ObjectId(...)` is accepted — mdbkit unwraps those
|
|
457
|
+
automatically, so you do not have to re-export.
|
|
458
|
+
|
|
415
459
|
---
|
|
416
460
|
|
|
417
461
|
### `mdbkit triage <log>`
|
|
418
462
|
|
|
419
|
-
|
|
463
|
+
**"Triage" means: quickly work out what is wrong and what to look at first.**
|
|
464
|
+
Run this when something has gone wrong — or has just gone wrong — and you need
|
|
465
|
+
one screen that says what happened, how bad it is, and where to look next.
|
|
466
|
+
**Defaults to the last 60 minutes of log time.**
|
|
420
467
|
|
|
421
468
|
| Option | Default | Description |
|
|
422
469
|
|---|---|---|
|
|
423
470
|
| `--window N` | 60 | Analyze the last N minutes of log time; `0` = the whole file |
|
|
424
471
|
| `--dbpath PATH` | auto | Override the data directory used for the disk check |
|
|
425
472
|
| `--no-sysprobe` | off | Skip local disk/memory/CPU probes — use when analyzing a log copied off the host |
|
|
473
|
+
| `--ftdc PATH` | | `diagnostic.data` directory — adds CPU, memory, cache, queue and connection history from MongoDB's own recorder |
|
|
474
|
+
| `--report FILE` | | Write a shareable `.md` or `.html` report instead of terminal output |
|
|
426
475
|
| `--json` | | Machine-readable output |
|
|
427
476
|
|
|
428
477
|
```bash
|
|
429
478
|
mdbkit triage /var/log/mongodb/mongod.log
|
|
430
479
|
mdbkit triage mongod.log --window 30
|
|
480
|
+
mdbkit triage mongod.log --ftdc /var/lib/mongodb/diagnostic.data
|
|
481
|
+
mdbkit triage mongod.log --report incident.html
|
|
431
482
|
mdbkit triage mongod.log --window 0 --no-sysprobe
|
|
432
483
|
```
|
|
433
484
|
|
|
434
485
|
---
|
|
435
486
|
|
|
487
|
+
### `mdbkit ftdc {summary|timeline|export} <path>`
|
|
488
|
+
|
|
489
|
+
Decodes `diagnostic.data` — **FTDC (Full-Time Diagnostic Data Capture)**, the
|
|
490
|
+
metrics recorder every mongod already runs. It holds CPU, memory, WiredTiger
|
|
491
|
+
cache, connection, queue and operation history for every node, with no
|
|
492
|
+
monitoring agent installed and no database connection. It is compressed BSON,
|
|
493
|
+
not encrypted; mdbkit decodes it offline.
|
|
494
|
+
|
|
495
|
+
| Action | Description |
|
|
496
|
+
|---|---|
|
|
497
|
+
| `summary` | min / avg / max / last per metric, plus per-second rates for counters |
|
|
498
|
+
| `timeline` | Values bucketed over time — shows *when* something spiked |
|
|
499
|
+
| `export` | CSV to stdout, for a spreadsheet or your own tooling |
|
|
500
|
+
|
|
501
|
+
| Option | Default | Description |
|
|
502
|
+
|---|---|---|
|
|
503
|
+
| `--metric LABEL` | all | Restrict to one metric (repeatable), e.g. `--metric conns.current` |
|
|
504
|
+
| `--step SECONDS` | 60 | Timeline bucket size |
|
|
505
|
+
| `--from` / `--to` | | Time bounds (same formats as `filter`) |
|
|
506
|
+
| `--json` | | Machine-readable output |
|
|
507
|
+
|
|
508
|
+
```bash
|
|
509
|
+
mdbkit ftdc summary /var/lib/mongodb/diagnostic.data
|
|
510
|
+
mdbkit ftdc timeline diagnostic.data --metric conns.current --step 300
|
|
511
|
+
mdbkit ftdc export diagnostic.data > metrics.csv
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
Metric labels include `ops.*` (insert/query/update/delete/getmore/command),
|
|
515
|
+
`conns.current`, `conns.available`, `queue.readers`, `queue.writers`,
|
|
516
|
+
`cache.usedBytes`, `cache.maxBytes`, `cache.dirtyBytes`, `tickets.*`,
|
|
517
|
+
`mem.residentMB`, and on Linux `sys.cpu.*` and `sys.mem.availableKB`.
|
|
518
|
+
|
|
519
|
+
The data directory can be copied off the host and analyzed elsewhere — it
|
|
520
|
+
contains metrics only, never document contents.
|
|
521
|
+
|
|
522
|
+
---
|
|
523
|
+
|
|
436
524
|
### `mdbkit export-script {schema|indexes}`
|
|
437
525
|
|
|
438
526
|
Prints a small `mongosh` script to stdout. **mdbkit never connects to your
|
|
@@ -452,12 +540,15 @@ mdbkit export-script schema > export_schema.js
|
|
|
452
540
|
Terminal output is and will remain first-class — this tool is built for the
|
|
453
541
|
Linux box the database actually runs on.
|
|
454
542
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
543
|
+
**Shipped in v0.2:** FTDC decoding, incident triage with system metrics,
|
|
544
|
+
query reconstruction (`--as-explain`), and shareable Markdown/HTML reports.
|
|
545
|
+
|
|
546
|
+
Next up:
|
|
547
|
+
* Per-shape drill-down (`mdbkit queries --shape N` with full detail).
|
|
548
|
+
* `serverStatus` snapshot digest for triage (two snapshots for true rates).
|
|
549
|
+
* Graduating the remaining beta detectors (checkpoints, eviction, flow
|
|
550
|
+
control) once validated against real incident logs — see
|
|
551
|
+
`docs/TESTING-PLAYBOOK.md`. Real logs very welcome.
|
|
461
552
|
|
|
462
553
|
mdbkit is validated against real-world structured logs (tens of thousands of
|
|
463
554
|
lines) in addition to its synthetic test fixtures.
|