mdbkit 0.6.0__tar.gz → 0.6.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.6.0 → mdbkit-0.6.1}/PKG-INFO +95 -27
- {mdbkit-0.6.0 → mdbkit-0.6.1}/README.md +94 -26
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/__init__.py +1 -1
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/analysis.py +75 -5
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/audit.py +33 -2
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/cli.py +2 -1
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/demo.py +9 -3
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/ftdc.py +9 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/lab.py +33 -4
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/parser.py +8 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/render.py +74 -15
- mdbkit-0.6.1/mdbkit/scripts.py +123 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/serverstatus.py +3 -1
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/shelljson.py +14 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/triage.py +284 -39
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit.egg-info/PKG-INFO +95 -27
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit.egg-info/SOURCES.txt +1 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/pyproject.toml +1 -1
- mdbkit-0.6.1/tests/test_real_servers.py +362 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/tests/test_triage.py +4 -2
- {mdbkit-0.6.0 → mdbkit-0.6.1}/tests/test_v060_hardening.py +1 -1
- mdbkit-0.6.0/mdbkit/scripts.py +0 -83
- {mdbkit-0.6.0 → mdbkit-0.6.1}/LICENSE +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/advisor.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/compare.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/explain.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/filtering.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/oslog.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/rebuild.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit/report.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit.egg-info/dependency_links.txt +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit.egg-info/entry_points.txt +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit.egg-info/requires.txt +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/mdbkit.egg-info/top_level.txt +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/setup.cfg +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/tests/test_demo_lab.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/tests/test_explain.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/tests/test_ftdc.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/tests/test_mdbkit.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/tests/test_oslog_serverstatus.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/tests/test_rebuild_report.py +0 -0
- {mdbkit-0.6.0 → mdbkit-0.6.1}/tests/test_render_e2e.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mdbkit
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.1
|
|
4
4
|
Summary: Offline toolkit for MongoDB 4.4 to 9.0 structured logs: slow-query shapes, index advice, incident triage, startup configuration audit, FTDC decoding. A spiritual successor to mtools' log tools.
|
|
5
5
|
Author: Saqib Ameen Subhan
|
|
6
6
|
License: MIT
|
|
@@ -36,7 +36,7 @@ Dynamic: license-file
|
|
|
36
36
|
deterministic index advice, incident triage, a startup configuration audit,
|
|
37
37
|
and diagnostic-data decoding. For MongoDB 4.4 through 8.x and 9.0, from the
|
|
38
38
|
terminal, without connecting to anything.
|
|
39
|
-
**[
|
|
39
|
+
**[Tested against real MongoDB 9.0.2, 8.3.11, 8.0.32 and 7.0.43](#compatibility)**
|
|
40
40
|
(October 2026).
|
|
41
41
|
|
|
42
42
|
A spiritual successor to mtools' log tools, which never learned to read the
|
|
@@ -266,29 +266,43 @@ updates — upgrades are always explicit.
|
|
|
266
266
|
|
|
267
267
|
## Compatibility
|
|
268
268
|
|
|
269
|
-
**
|
|
270
|
-
|
|
271
|
-
format, so anything from **4.4** onwards
|
|
272
|
-
text logs and are not supported.
|
|
269
|
+
**Tested against (October 2026):** MongoDB **9.0.2**, **8.3.11**, **8.0.32**
|
|
270
|
+
(LTS) and **7.0.43** (LTS), the newest release in each series at the time.
|
|
271
|
+
mdbkit reads the structured JSON log format, so anything from **4.4** onwards
|
|
272
|
+
works; 4.2 and earlier wrote plain text logs and are not supported.
|
|
273
273
|
|
|
274
274
|
| MongoDB | What mdbkit uses from it |
|
|
275
275
|
|---|---|
|
|
276
276
|
| 4.4 – 7.0 | Everything except the 8.x-only fields below |
|
|
277
277
|
| 8.0 | `workingMillis` (time executing, as distinct from waiting), `queues.execution.totalTimeQueuedMicros` (ticket queue time), `queryShapeHash` (usable with `setQuerySettings`), `planCacheShapeHash`, the 8.0 transparent-huge-page guidance |
|
|
278
278
|
| 8.1+ | `<stage>Spills` / `<stage>SpilledBytes` (disk spills per stage) |
|
|
279
|
-
| 8.3+ |
|
|
280
|
-
| 9.0 |
|
|
281
|
-
|
|
282
|
-
When a field is missing
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
**How
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
279
|
+
| 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
|
+
| 9.0 | Same log fields as 8.3. Adds a few fields mdbkit does not use yet (`delinquencyInfo`, `queues.ingress`) |
|
|
281
|
+
|
|
282
|
+
When a field is missing because the log predates it, that part of the output
|
|
283
|
+
is left out. It is never guessed. FTDC decoding and `serverstatus` read
|
|
284
|
+
concurrency tickets from either the older `wiredTiger.concurrentTransactions`
|
|
285
|
+
or the newer `queues.execution` layout.
|
|
286
|
+
|
|
287
|
+
**How it was tested.** Official MongoDB builds of each version were run with
|
|
288
|
+
`mdbkit lab` (a three-node replica set and a standalone), seeded, and put
|
|
289
|
+
through a workload built to produce every field above: unindexed queries,
|
|
290
|
+
sorts and groups forced to spill to disk, writes blocked behind `fsyncLock` so
|
|
291
|
+
they wait rather than work, long-running server-side JavaScript, a clean
|
|
292
|
+
restart and a `kill -9`. Every mdbkit command was then run on the resulting
|
|
293
|
+
logs, `diagnostic.data`, serverStatus and explain output and `getLog`
|
|
294
|
+
captures, and compared with what the server actually did. Trimmed copies of
|
|
295
|
+
that output are in [`tests/fixtures/real/`](tests/fixtures/real/) and run with
|
|
296
|
+
every test.
|
|
297
|
+
|
|
298
|
+
> **Correction.** The 0.6.0 README and release notes said "last checked
|
|
299
|
+
> against 9.0.2, 8.3.13, 8.0.34 and 7.0.45". Three of those version numbers
|
|
300
|
+
> were wrong: MongoDB's release index has no 8.3.13, 8.0.34 or 7.0.45. That
|
|
301
|
+
> release was also checked against release notes and server source only, not
|
|
302
|
+
> a running server. Testing against real servers in 0.6.1 found several bugs
|
|
303
|
+
> 0.6.0 had missed (see the release notes).
|
|
304
|
+
|
|
305
|
+
If mdbkit misreads a line from your deployment, please
|
|
292
306
|
[open an issue](../../issues) with the line (redact as you like).
|
|
293
307
|
|
|
294
308
|
---
|
|
@@ -323,7 +337,7 @@ not help.
|
|
|
323
337
|
mdbkit export-script indexes > export_indexes.js
|
|
324
338
|
mdbkit export-script schema > export_schema.js
|
|
325
339
|
|
|
326
|
-
mongosh --quiet
|
|
340
|
+
mongosh --quiet "mongodb://your_db_host:27017/" \
|
|
327
341
|
--username your_username --password your_password \
|
|
328
342
|
--authenticationDatabase admin \
|
|
329
343
|
--eval "$(cat export_indexes.js)" > indexes.json # repeat for schema
|
|
@@ -570,6 +584,13 @@ query with different parameters is counted once.
|
|
|
570
584
|
| `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 |
|
|
571
585
|
| `shape` | Fields and operators queried, with the sort |
|
|
572
586
|
|
|
587
|
+
Two kinds of row are worth knowing about. A `getMore(find)` or
|
|
588
|
+
`getMore(aggregate)` row is a cursor fetching more results; it is grouped
|
|
589
|
+
under the shape of the query that opened the cursor. Slow `insert` rows are
|
|
590
|
+
included even though no index can speed up an insert: a slow insert is still
|
|
591
|
+
latency your application saw, and on 8.0+ the `--shape` view says whether it
|
|
592
|
+
was executing or waiting (on locks, flow control or write concern).
|
|
593
|
+
|
|
573
594
|
```bash
|
|
574
595
|
mdbkit queries mongod.log
|
|
575
596
|
mdbkit queries mongod.log --sort scanRatio --limit 10
|
|
@@ -813,6 +834,29 @@ mdbkit triage mongod.log --report incident.html
|
|
|
813
834
|
mdbkit triage mongod.log --window 0 --no-sysprobe
|
|
814
835
|
```
|
|
815
836
|
|
|
837
|
+
**Restarts and crashes.** A restart after a clean shutdown is a WARN; a start
|
|
838
|
+
with no clean shutdown before it is a CRIT, because that is what a crash,
|
|
839
|
+
`kill -9` or OOM kill looks like. mongod itself records whether its previous
|
|
840
|
+
shutdown was clean, so mdbkit can tell even when the crash happened before
|
|
841
|
+
the log you are reading begins. The first election of a newly initiated
|
|
842
|
+
replica set is reported as INFO, not as instability.
|
|
843
|
+
|
|
844
|
+
**Hosts running several mongods.** Run mdbkit once per instance, on that
|
|
845
|
+
instance's own log; don't pass several instances' logs in one command,
|
|
846
|
+
because several files are read as one stream (that is for the rotated logs of
|
|
847
|
+
one instance, or the members of one replica set). When several mongods run on
|
|
848
|
+
the host, `triage` uses the pid and dbPath in the log's startup line to pick
|
|
849
|
+
the right process for its memory, uptime and disk checks, and when
|
|
850
|
+
`--oslog` shows an OOM kill it says whether the killed pid was this
|
|
851
|
+
instance or another one.
|
|
852
|
+
|
|
853
|
+
```bash
|
|
854
|
+
for log in /var/log/mongodb/*/mongod.log; do
|
|
855
|
+
echo "== $log"
|
|
856
|
+
mdbkit triage "$log" --only CRIT,WARN
|
|
857
|
+
done
|
|
858
|
+
```
|
|
859
|
+
|
|
816
860
|
---
|
|
817
861
|
|
|
818
862
|
### `mdbkit audit <log>`
|
|
@@ -883,6 +927,10 @@ mdbkit ftdc timeline diagnostic.data --metric conns.current --step 300
|
|
|
883
927
|
mdbkit ftdc export diagnostic.data > metrics.csv
|
|
884
928
|
```
|
|
885
929
|
|
|
930
|
+
In `timeline`, gauges (connections, cache bytes, tickets) show the peak in
|
|
931
|
+
each bucket and cumulative counters (`ops.*`, `sys.cpu.*`) show their rate
|
|
932
|
+
per second over it.
|
|
933
|
+
|
|
886
934
|
Metric labels include `ops.*` (insert/query/update/delete/getmore/command),
|
|
887
935
|
`conns.current`, `conns.available`, `queue.readers`, `queue.writers`,
|
|
888
936
|
`cache.usedBytes`, `cache.maxBytes`, `cache.dirtyBytes`, `tickets.*`,
|
|
@@ -1016,8 +1064,8 @@ mdbkit triage $(mdbkit lab logs) # all three as one stream
|
|
|
1016
1064
|
mdbkit loginfo $(mdbkit lab logs | sed -n 2p) # a specific secondary
|
|
1017
1065
|
```
|
|
1018
1066
|
|
|
1019
|
-
**A single node**, when you do not need replication
|
|
1020
|
-
|
|
1067
|
+
**A single node**, when you do not need replication. It starts faster, and
|
|
1068
|
+
`start` works without `mongosh` (`seed` still needs it):
|
|
1021
1069
|
|
|
1022
1070
|
```bash
|
|
1023
1071
|
mdbkit lab start --standalone
|
|
@@ -1150,7 +1198,9 @@ role and process memory. Tickets are read from either the older
|
|
|
1150
1198
|
mongosh prints when you run `db.serverStatus()` and copy the output:
|
|
1151
1199
|
unquoted keys, `Long('42')`, `ISODate(...)`, `Timestamp({...})`. A file
|
|
1152
1200
|
redirected in Windows PowerShell (UTF-16) works too. Nothing in the file is
|
|
1153
|
-
ever evaluated; it is tokenised as data.
|
|
1201
|
+
ever evaluated; it is tokenised as data. Dumps taken with the 0.6.0 export
|
|
1202
|
+
script, which wrote 64-bit counters as `{"low": …, "high": …}` objects, are
|
|
1203
|
+
read correctly too.
|
|
1154
1204
|
|
|
1155
1205
|
**Two dumps give true rates.** Almost everything in serverStatus is cumulative
|
|
1156
1206
|
since process start, so a single dump only yields lifetime averages:
|
|
@@ -1211,13 +1261,22 @@ duration moving by more than 20%.
|
|
|
1211
1261
|
### `mdbkit export-script {schema|indexes}`
|
|
1212
1262
|
|
|
1213
1263
|
Prints a small `mongosh` script to stdout. **mdbkit never connects to your
|
|
1214
|
-
database
|
|
1215
|
-
first. Both are read-only
|
|
1216
|
-
document values**.
|
|
1264
|
+
database**. You run these yourself, so you can read exactly what they do
|
|
1265
|
+
first. Both are read-only. `schema` exports **field names and types only,
|
|
1266
|
+
never document values**. `indexes` exports the index definitions from
|
|
1267
|
+
`getIndexes()`; a partial index's filter expression can contain literal
|
|
1268
|
+
values.
|
|
1269
|
+
|
|
1270
|
+
Both cover **every database you can read** (`admin`, `config` and `local`
|
|
1271
|
+
skipped) and key collections by full namespace, so it does not matter which
|
|
1272
|
+
database mongosh connects to. To export one database only, set `ONLY_DB` at
|
|
1273
|
+
the top of the script. The `serverstatus` script writes relaxed Extended
|
|
1274
|
+
JSON, so 64-bit counters come out as plain numbers.
|
|
1217
1275
|
|
|
1218
1276
|
```bash
|
|
1219
1277
|
mdbkit export-script indexes > export_indexes.js
|
|
1220
1278
|
mdbkit export-script schema > export_schema.js
|
|
1279
|
+
mdbkit export-script serverstatus > export_serverstatus.js
|
|
1221
1280
|
```
|
|
1222
1281
|
|
|
1223
1282
|
---
|
|
@@ -1227,6 +1286,10 @@ mdbkit export-script schema > export_schema.js
|
|
|
1227
1286
|
Terminal output is and will remain first-class — this tool is built for the
|
|
1228
1287
|
Linux box the database actually runs on.
|
|
1229
1288
|
|
|
1289
|
+
**Shipped in v0.6.1:** tested against real MongoDB 7.0, 8.0, 8.3 and 9.0
|
|
1290
|
+
servers, with the bugs that turned up fixed; crash vs clean restart
|
|
1291
|
+
detection; correct behaviour on hosts running many mongods.
|
|
1292
|
+
|
|
1230
1293
|
**Shipped in v0.6:** MongoDB 8.x/9.0 support (executing vs waiting time,
|
|
1231
1294
|
query shape hashes, disk spills, peak memory, in-progress operations, the
|
|
1232
1295
|
8.0 ticket layout in FTDC), the `audit` command, mongosh-paste input, and a
|
|
@@ -1237,6 +1300,10 @@ shareable reports.
|
|
|
1237
1300
|
|
|
1238
1301
|
Next up, roughly in order:
|
|
1239
1302
|
|
|
1303
|
+
* **Hosts running many mongods.** One line per instance (health, restarts,
|
|
1304
|
+
slow time, startup warnings), the WiredTiger cache sizes of every instance
|
|
1305
|
+
added up against the host's RAM (54 instances on default settings would
|
|
1306
|
+
each claim about half of it), and each OOM kill matched to its instance.
|
|
1240
1307
|
* **Sharded clusters.** `mongos` logs are a different shape, and the classic
|
|
1241
1308
|
sharded failure — a query with no shard key fanning out to every shard — is
|
|
1242
1309
|
visible in the log. Also chunk migrations, balancer windows and jumbo
|
|
@@ -1251,7 +1318,8 @@ Next up, roughly in order:
|
|
|
1251
1318
|
`docs/TESTING-PLAYBOOK.md`. Real logs and metrics very welcome.
|
|
1252
1319
|
|
|
1253
1320
|
mdbkit is validated against real-world structured logs (tens of thousands of
|
|
1254
|
-
lines) in addition to its synthetic test fixtures
|
|
1321
|
+
lines) in addition to its synthetic test fixtures, and its tests include real
|
|
1322
|
+
output from MongoDB 7.0.43, 8.0.32, 8.3.11 and 9.0.2.
|
|
1255
1323
|
|
|
1256
1324
|
## Bugs, feature requests, questions
|
|
1257
1325
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
deterministic index advice, incident triage, a startup configuration audit,
|
|
10
10
|
and diagnostic-data decoding. For MongoDB 4.4 through 8.x and 9.0, from the
|
|
11
11
|
terminal, without connecting to anything.
|
|
12
|
-
**[
|
|
12
|
+
**[Tested against real MongoDB 9.0.2, 8.3.11, 8.0.32 and 7.0.43](#compatibility)**
|
|
13
13
|
(October 2026).
|
|
14
14
|
|
|
15
15
|
A spiritual successor to mtools' log tools, which never learned to read the
|
|
@@ -239,29 +239,43 @@ updates — upgrades are always explicit.
|
|
|
239
239
|
|
|
240
240
|
## Compatibility
|
|
241
241
|
|
|
242
|
-
**
|
|
243
|
-
|
|
244
|
-
format, so anything from **4.4** onwards
|
|
245
|
-
text logs and are not supported.
|
|
242
|
+
**Tested against (October 2026):** MongoDB **9.0.2**, **8.3.11**, **8.0.32**
|
|
243
|
+
(LTS) and **7.0.43** (LTS), the newest release in each series at the time.
|
|
244
|
+
mdbkit reads the structured JSON log format, so anything from **4.4** onwards
|
|
245
|
+
works; 4.2 and earlier wrote plain text logs and are not supported.
|
|
246
246
|
|
|
247
247
|
| MongoDB | What mdbkit uses from it |
|
|
248
248
|
|---|---|
|
|
249
249
|
| 4.4 – 7.0 | Everything except the 8.x-only fields below |
|
|
250
250
|
| 8.0 | `workingMillis` (time executing, as distinct from waiting), `queues.execution.totalTimeQueuedMicros` (ticket queue time), `queryShapeHash` (usable with `setQuerySettings`), `planCacheShapeHash`, the 8.0 transparent-huge-page guidance |
|
|
251
251
|
| 8.1+ | `<stage>Spills` / `<stage>SpilledBytes` (disk spills per stage) |
|
|
252
|
-
| 8.3+ |
|
|
253
|
-
| 9.0 |
|
|
254
|
-
|
|
255
|
-
When a field is missing
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
**How
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
252
|
+
| 8.3+ | "Slow in-progress query" lines (id 1794200, component `SLOWPROG`), logged by default for operations still running after 5 s (`--defaultSlowInProgMS`), and `peakTrackedMemBytes` |
|
|
253
|
+
| 9.0 | Same log fields as 8.3. Adds a few fields mdbkit does not use yet (`delinquencyInfo`, `queues.ingress`) |
|
|
254
|
+
|
|
255
|
+
When a field is missing because the log predates it, that part of the output
|
|
256
|
+
is left out. It is never guessed. FTDC decoding and `serverstatus` read
|
|
257
|
+
concurrency tickets from either the older `wiredTiger.concurrentTransactions`
|
|
258
|
+
or the newer `queues.execution` layout.
|
|
259
|
+
|
|
260
|
+
**How it was tested.** Official MongoDB builds of each version were run with
|
|
261
|
+
`mdbkit lab` (a three-node replica set and a standalone), seeded, and put
|
|
262
|
+
through a workload built to produce every field above: unindexed queries,
|
|
263
|
+
sorts and groups forced to spill to disk, writes blocked behind `fsyncLock` so
|
|
264
|
+
they wait rather than work, long-running server-side JavaScript, a clean
|
|
265
|
+
restart and a `kill -9`. Every mdbkit command was then run on the resulting
|
|
266
|
+
logs, `diagnostic.data`, serverStatus and explain output and `getLog`
|
|
267
|
+
captures, and compared with what the server actually did. Trimmed copies of
|
|
268
|
+
that output are in [`tests/fixtures/real/`](tests/fixtures/real/) and run with
|
|
269
|
+
every test.
|
|
270
|
+
|
|
271
|
+
> **Correction.** The 0.6.0 README and release notes said "last checked
|
|
272
|
+
> against 9.0.2, 8.3.13, 8.0.34 and 7.0.45". Three of those version numbers
|
|
273
|
+
> were wrong: MongoDB's release index has no 8.3.13, 8.0.34 or 7.0.45. That
|
|
274
|
+
> release was also checked against release notes and server source only, not
|
|
275
|
+
> a running server. Testing against real servers in 0.6.1 found several bugs
|
|
276
|
+
> 0.6.0 had missed (see the release notes).
|
|
277
|
+
|
|
278
|
+
If mdbkit misreads a line from your deployment, please
|
|
265
279
|
[open an issue](../../issues) with the line (redact as you like).
|
|
266
280
|
|
|
267
281
|
---
|
|
@@ -296,7 +310,7 @@ not help.
|
|
|
296
310
|
mdbkit export-script indexes > export_indexes.js
|
|
297
311
|
mdbkit export-script schema > export_schema.js
|
|
298
312
|
|
|
299
|
-
mongosh --quiet
|
|
313
|
+
mongosh --quiet "mongodb://your_db_host:27017/" \
|
|
300
314
|
--username your_username --password your_password \
|
|
301
315
|
--authenticationDatabase admin \
|
|
302
316
|
--eval "$(cat export_indexes.js)" > indexes.json # repeat for schema
|
|
@@ -543,6 +557,13 @@ query with different parameters is counted once.
|
|
|
543
557
|
| `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 |
|
|
544
558
|
| `shape` | Fields and operators queried, with the sort |
|
|
545
559
|
|
|
560
|
+
Two kinds of row are worth knowing about. A `getMore(find)` or
|
|
561
|
+
`getMore(aggregate)` row is a cursor fetching more results; it is grouped
|
|
562
|
+
under the shape of the query that opened the cursor. Slow `insert` rows are
|
|
563
|
+
included even though no index can speed up an insert: a slow insert is still
|
|
564
|
+
latency your application saw, and on 8.0+ the `--shape` view says whether it
|
|
565
|
+
was executing or waiting (on locks, flow control or write concern).
|
|
566
|
+
|
|
546
567
|
```bash
|
|
547
568
|
mdbkit queries mongod.log
|
|
548
569
|
mdbkit queries mongod.log --sort scanRatio --limit 10
|
|
@@ -786,6 +807,29 @@ mdbkit triage mongod.log --report incident.html
|
|
|
786
807
|
mdbkit triage mongod.log --window 0 --no-sysprobe
|
|
787
808
|
```
|
|
788
809
|
|
|
810
|
+
**Restarts and crashes.** A restart after a clean shutdown is a WARN; a start
|
|
811
|
+
with no clean shutdown before it is a CRIT, because that is what a crash,
|
|
812
|
+
`kill -9` or OOM kill looks like. mongod itself records whether its previous
|
|
813
|
+
shutdown was clean, so mdbkit can tell even when the crash happened before
|
|
814
|
+
the log you are reading begins. The first election of a newly initiated
|
|
815
|
+
replica set is reported as INFO, not as instability.
|
|
816
|
+
|
|
817
|
+
**Hosts running several mongods.** Run mdbkit once per instance, on that
|
|
818
|
+
instance's own log; don't pass several instances' logs in one command,
|
|
819
|
+
because several files are read as one stream (that is for the rotated logs of
|
|
820
|
+
one instance, or the members of one replica set). When several mongods run on
|
|
821
|
+
the host, `triage` uses the pid and dbPath in the log's startup line to pick
|
|
822
|
+
the right process for its memory, uptime and disk checks, and when
|
|
823
|
+
`--oslog` shows an OOM kill it says whether the killed pid was this
|
|
824
|
+
instance or another one.
|
|
825
|
+
|
|
826
|
+
```bash
|
|
827
|
+
for log in /var/log/mongodb/*/mongod.log; do
|
|
828
|
+
echo "== $log"
|
|
829
|
+
mdbkit triage "$log" --only CRIT,WARN
|
|
830
|
+
done
|
|
831
|
+
```
|
|
832
|
+
|
|
789
833
|
---
|
|
790
834
|
|
|
791
835
|
### `mdbkit audit <log>`
|
|
@@ -856,6 +900,10 @@ mdbkit ftdc timeline diagnostic.data --metric conns.current --step 300
|
|
|
856
900
|
mdbkit ftdc export diagnostic.data > metrics.csv
|
|
857
901
|
```
|
|
858
902
|
|
|
903
|
+
In `timeline`, gauges (connections, cache bytes, tickets) show the peak in
|
|
904
|
+
each bucket and cumulative counters (`ops.*`, `sys.cpu.*`) show their rate
|
|
905
|
+
per second over it.
|
|
906
|
+
|
|
859
907
|
Metric labels include `ops.*` (insert/query/update/delete/getmore/command),
|
|
860
908
|
`conns.current`, `conns.available`, `queue.readers`, `queue.writers`,
|
|
861
909
|
`cache.usedBytes`, `cache.maxBytes`, `cache.dirtyBytes`, `tickets.*`,
|
|
@@ -989,8 +1037,8 @@ mdbkit triage $(mdbkit lab logs) # all three as one stream
|
|
|
989
1037
|
mdbkit loginfo $(mdbkit lab logs | sed -n 2p) # a specific secondary
|
|
990
1038
|
```
|
|
991
1039
|
|
|
992
|
-
**A single node**, when you do not need replication
|
|
993
|
-
|
|
1040
|
+
**A single node**, when you do not need replication. It starts faster, and
|
|
1041
|
+
`start` works without `mongosh` (`seed` still needs it):
|
|
994
1042
|
|
|
995
1043
|
```bash
|
|
996
1044
|
mdbkit lab start --standalone
|
|
@@ -1123,7 +1171,9 @@ role and process memory. Tickets are read from either the older
|
|
|
1123
1171
|
mongosh prints when you run `db.serverStatus()` and copy the output:
|
|
1124
1172
|
unquoted keys, `Long('42')`, `ISODate(...)`, `Timestamp({...})`. A file
|
|
1125
1173
|
redirected in Windows PowerShell (UTF-16) works too. Nothing in the file is
|
|
1126
|
-
ever evaluated; it is tokenised as data.
|
|
1174
|
+
ever evaluated; it is tokenised as data. Dumps taken with the 0.6.0 export
|
|
1175
|
+
script, which wrote 64-bit counters as `{"low": …, "high": …}` objects, are
|
|
1176
|
+
read correctly too.
|
|
1127
1177
|
|
|
1128
1178
|
**Two dumps give true rates.** Almost everything in serverStatus is cumulative
|
|
1129
1179
|
since process start, so a single dump only yields lifetime averages:
|
|
@@ -1184,13 +1234,22 @@ duration moving by more than 20%.
|
|
|
1184
1234
|
### `mdbkit export-script {schema|indexes}`
|
|
1185
1235
|
|
|
1186
1236
|
Prints a small `mongosh` script to stdout. **mdbkit never connects to your
|
|
1187
|
-
database
|
|
1188
|
-
first. Both are read-only
|
|
1189
|
-
document values**.
|
|
1237
|
+
database**. You run these yourself, so you can read exactly what they do
|
|
1238
|
+
first. Both are read-only. `schema` exports **field names and types only,
|
|
1239
|
+
never document values**. `indexes` exports the index definitions from
|
|
1240
|
+
`getIndexes()`; a partial index's filter expression can contain literal
|
|
1241
|
+
values.
|
|
1242
|
+
|
|
1243
|
+
Both cover **every database you can read** (`admin`, `config` and `local`
|
|
1244
|
+
skipped) and key collections by full namespace, so it does not matter which
|
|
1245
|
+
database mongosh connects to. To export one database only, set `ONLY_DB` at
|
|
1246
|
+
the top of the script. The `serverstatus` script writes relaxed Extended
|
|
1247
|
+
JSON, so 64-bit counters come out as plain numbers.
|
|
1190
1248
|
|
|
1191
1249
|
```bash
|
|
1192
1250
|
mdbkit export-script indexes > export_indexes.js
|
|
1193
1251
|
mdbkit export-script schema > export_schema.js
|
|
1252
|
+
mdbkit export-script serverstatus > export_serverstatus.js
|
|
1194
1253
|
```
|
|
1195
1254
|
|
|
1196
1255
|
---
|
|
@@ -1200,6 +1259,10 @@ mdbkit export-script schema > export_schema.js
|
|
|
1200
1259
|
Terminal output is and will remain first-class — this tool is built for the
|
|
1201
1260
|
Linux box the database actually runs on.
|
|
1202
1261
|
|
|
1262
|
+
**Shipped in v0.6.1:** tested against real MongoDB 7.0, 8.0, 8.3 and 9.0
|
|
1263
|
+
servers, with the bugs that turned up fixed; crash vs clean restart
|
|
1264
|
+
detection; correct behaviour on hosts running many mongods.
|
|
1265
|
+
|
|
1203
1266
|
**Shipped in v0.6:** MongoDB 8.x/9.0 support (executing vs waiting time,
|
|
1204
1267
|
query shape hashes, disk spills, peak memory, in-progress operations, the
|
|
1205
1268
|
8.0 ticket layout in FTDC), the `audit` command, mongosh-paste input, and a
|
|
@@ -1210,6 +1273,10 @@ shareable reports.
|
|
|
1210
1273
|
|
|
1211
1274
|
Next up, roughly in order:
|
|
1212
1275
|
|
|
1276
|
+
* **Hosts running many mongods.** One line per instance (health, restarts,
|
|
1277
|
+
slow time, startup warnings), the WiredTiger cache sizes of every instance
|
|
1278
|
+
added up against the host's RAM (54 instances on default settings would
|
|
1279
|
+
each claim about half of it), and each OOM kill matched to its instance.
|
|
1213
1280
|
* **Sharded clusters.** `mongos` logs are a different shape, and the classic
|
|
1214
1281
|
sharded failure — a query with no shard key fanning out to every shard — is
|
|
1215
1282
|
visible in the log. Also chunk migrations, balancer windows and jumbo
|
|
@@ -1224,7 +1291,8 @@ Next up, roughly in order:
|
|
|
1224
1291
|
`docs/TESTING-PLAYBOOK.md`. Real logs and metrics very welcome.
|
|
1225
1292
|
|
|
1226
1293
|
mdbkit is validated against real-world structured logs (tens of thousands of
|
|
1227
|
-
lines) in addition to its synthetic test fixtures
|
|
1294
|
+
lines) in addition to its synthetic test fixtures, and its tests include real
|
|
1295
|
+
output from MongoDB 7.0.43, 8.0.32, 8.3.11 and 9.0.2.
|
|
1228
1296
|
|
|
1229
1297
|
## Bugs, feature requests, questions
|
|
1230
1298
|
|
|
@@ -10,7 +10,7 @@ Three analyses, mirroring the most-used mtools workflows:
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
12
|
import math
|
|
13
|
-
from collections import Counter, defaultdict
|
|
13
|
+
from collections import Counter, OrderedDict, defaultdict
|
|
14
14
|
from dataclasses import dataclass, field
|
|
15
15
|
from typing import Dict, List, Optional, Tuple
|
|
16
16
|
|
|
@@ -148,7 +148,12 @@ def extract_shape(entry: LogEntry) -> Optional[QueryShape]:
|
|
|
148
148
|
operation = "distinct"
|
|
149
149
|
filter_doc = command.get("query") or {}
|
|
150
150
|
elif "getMore" in command:
|
|
151
|
-
|
|
151
|
+
# Real logs carry the query that opened the cursor next to the
|
|
152
|
+
# command (attr.originatingCommand), not inside it; older captures
|
|
153
|
+
# and some tools nest it. Without it every getMore is shape "{}".
|
|
154
|
+
origin = attr.get("originatingCommand")
|
|
155
|
+
if not isinstance(origin, dict):
|
|
156
|
+
origin = command.get("originatingCommand")
|
|
152
157
|
if isinstance(origin, dict):
|
|
153
158
|
fake = LogEntry(
|
|
154
159
|
ts=entry.ts, severity=entry.severity, component=entry.component,
|
|
@@ -366,6 +371,52 @@ class ShapeStats:
|
|
|
366
371
|
}
|
|
367
372
|
|
|
368
373
|
|
|
374
|
+
class BatchDedup:
|
|
375
|
+
"""Recognise the second log line of one slow write.
|
|
376
|
+
|
|
377
|
+
MongoDB logs a slow update or delete twice: a WRITE entry for the
|
|
378
|
+
statement (with docsExamined and the plan) and then a COMMAND entry for
|
|
379
|
+
the whole batch (ns "<db>.$cmd", command {update: <coll>, updates: [...]})
|
|
380
|
+
on the same connection. Counting both doubles every write's count and
|
|
381
|
+
time. The WRITE line is kept; the batch line that follows it is the
|
|
382
|
+
duplicate.
|
|
383
|
+
|
|
384
|
+
Lines are paired by connection and collection, not opid: 9.0 logs an
|
|
385
|
+
opid on both lines, 8.0 and earlier on neither. A connection runs its
|
|
386
|
+
operations one at a time, so the batch line always follows its WRITE
|
|
387
|
+
lines.
|
|
388
|
+
"""
|
|
389
|
+
|
|
390
|
+
BATCH_COMMANDS = ("update", "delete")
|
|
391
|
+
|
|
392
|
+
def __init__(self, remember: int = 20000):
|
|
393
|
+
self.remember = remember
|
|
394
|
+
self._pending: "OrderedDict[str, str]" = OrderedDict() # ctx -> ns
|
|
395
|
+
|
|
396
|
+
def is_duplicate(self, entry: LogEntry) -> bool:
|
|
397
|
+
ctx = entry.ctx or ""
|
|
398
|
+
if entry.component == "WRITE":
|
|
399
|
+
ns = text(entry.attr.get("ns"))
|
|
400
|
+
if ctx and ns:
|
|
401
|
+
self._pending[ctx] = ns
|
|
402
|
+
self._pending.move_to_end(ctx)
|
|
403
|
+
if len(self._pending) > self.remember:
|
|
404
|
+
self._pending.popitem(last=False)
|
|
405
|
+
return False
|
|
406
|
+
pending = self._pending.pop(ctx, None)
|
|
407
|
+
if pending is None or entry.component != "COMMAND":
|
|
408
|
+
return False
|
|
409
|
+
cmd = entry.attr.get("command")
|
|
410
|
+
if not isinstance(cmd, dict):
|
|
411
|
+
return False
|
|
412
|
+
for name in self.BATCH_COMMANDS:
|
|
413
|
+
coll = cmd.get(name)
|
|
414
|
+
if isinstance(coll, str) and name + "s" in cmd:
|
|
415
|
+
db = text(cmd.get("$db")) or text(entry.attr.get("ns")).split(".", 1)[0]
|
|
416
|
+
return pending == "%s.%s" % (db, coll)
|
|
417
|
+
return False
|
|
418
|
+
|
|
419
|
+
|
|
369
420
|
class QueryAggregator:
|
|
370
421
|
NOISE_OPS = frozenset({
|
|
371
422
|
"hello", "isMaster", "ismaster", "ping", "endSessions", "saslStart",
|
|
@@ -390,6 +441,7 @@ class QueryAggregator:
|
|
|
390
441
|
self.include_system = include_system
|
|
391
442
|
self.shapes: Dict[QueryShape, ShapeStats] = {}
|
|
392
443
|
self.skipped_system = 0
|
|
444
|
+
self.dedup = BatchDedup()
|
|
393
445
|
|
|
394
446
|
@classmethod
|
|
395
447
|
def is_system_ns(cls, ns: str) -> bool:
|
|
@@ -401,10 +453,19 @@ class QueryAggregator:
|
|
|
401
453
|
def consume(self, entry: LogEntry):
|
|
402
454
|
if not entry.is_slow_query:
|
|
403
455
|
return
|
|
456
|
+
if self.dedup.is_duplicate(entry):
|
|
457
|
+
return
|
|
404
458
|
if num(entry.attr.get("durationMillis")) < self.min_ms:
|
|
405
459
|
return
|
|
406
460
|
shape = extract_shape(entry)
|
|
407
|
-
if shape is None
|
|
461
|
+
if shape is None:
|
|
462
|
+
return
|
|
463
|
+
# Slow inserts stay in: no index can fix them, but a 3 s insert is
|
|
464
|
+
# still a latency problem (lock waits, write concern, disk), and on
|
|
465
|
+
# 8.0+ the executing/waiting split says which.
|
|
466
|
+
if not shape.ns:
|
|
467
|
+
# Commands not run against any collection (e.g. a driver
|
|
468
|
+
# handshake probing for an unknown command). Not a query shape.
|
|
408
469
|
return
|
|
409
470
|
if shape.operation in self.NOISE_OPS and not shape.filter_fields:
|
|
410
471
|
return
|
|
@@ -614,7 +675,8 @@ class LogSummary:
|
|
|
614
675
|
severity_counts: Counter = field(default_factory=Counter)
|
|
615
676
|
component_counts: Counter = field(default_factory=Counter)
|
|
616
677
|
slow_queries: int = 0
|
|
617
|
-
|
|
678
|
+
user_slow_queries: int = 0
|
|
679
|
+
slowest_ms: int = 0 # on user namespaces only
|
|
618
680
|
slow_in_progress: int = 0
|
|
619
681
|
connections_accepted: int = 0
|
|
620
682
|
warnings: int = 0
|
|
@@ -626,6 +688,7 @@ class LogSummary:
|
|
|
626
688
|
"versions": self.versions,
|
|
627
689
|
"hosts": self.host_info,
|
|
628
690
|
"slowQueries": self.slow_queries,
|
|
691
|
+
"userSlowQueries": self.user_slow_queries,
|
|
629
692
|
"slowInProgress": self.slow_in_progress,
|
|
630
693
|
"slowestMs": self.slowest_ms,
|
|
631
694
|
"connectionsAccepted": self.connections_accepted,
|
|
@@ -663,6 +726,13 @@ class SummaryAggregator:
|
|
|
663
726
|
s.connections_accepted += 1
|
|
664
727
|
if entry.is_slow_query:
|
|
665
728
|
s.slow_queries += 1
|
|
666
|
-
|
|
729
|
+
ns = text(entry.attr.get("ns"))
|
|
730
|
+
# Internal operations (replication getMores on the oplog,
|
|
731
|
+
# awaitable hello) wait by design; counting them as "slowest"
|
|
732
|
+
# reports a 10 s long-poll as the worst query.
|
|
733
|
+
if ns and not QueryAggregator.is_system_ns(ns):
|
|
734
|
+
s.user_slow_queries += 1
|
|
735
|
+
s.slowest_ms = max(s.slowest_ms,
|
|
736
|
+
int(num(entry.attr.get("durationMillis"))))
|
|
667
737
|
elif entry.msg_id == ID_SLOW_IN_PROGRESS:
|
|
668
738
|
s.slow_in_progress += 1
|
|
@@ -12,7 +12,8 @@ last restart has already rotated away — and explains each one.
|
|
|
12
12
|
|
|
13
13
|
The message ids below are taken from the MongoDB server source
|
|
14
14
|
(startup_warnings_mongod.cpp / startup_warnings_common.cpp) for 6.0, 7.0 and
|
|
15
|
-
8.x
|
|
15
|
+
8.x, and checked against what real 7.0.43, 8.0.32, 8.3.11 and 9.0.2 servers
|
|
16
|
+
log. Unknown startup warnings are still reported, with MongoDB's own text.
|
|
16
17
|
|
|
17
18
|
Offline and read-only like every other analysis command.
|
|
18
19
|
"""
|
|
@@ -96,6 +97,9 @@ KNOWN: Dict[int, tuple] = {
|
|
|
96
97
|
"Set vm.swappiness to 0 or 1; swapping the WiredTiger cache "
|
|
97
98
|
"is far slower than evicting from it."),
|
|
98
99
|
22161: ("openvz", "INFO", "Running under OpenVZ", "Known issues on old RHEL kernels."),
|
|
100
|
+
22297: ("xfs", "WARN", "WiredTiger is not on XFS",
|
|
101
|
+
"MongoDB strongly recommends XFS for WiredTiger; ext4 is known to "
|
|
102
|
+
"stall under heavy checkpointing."),
|
|
99
103
|
# build / mode
|
|
100
104
|
22123: ("32-bit", "WARN", "32-bit binary", "Unsupported for production."),
|
|
101
105
|
22135: ("32-bit", "WARN", "32-bit binary on a 64-bit OS", "Unsupported for production."),
|
|
@@ -130,13 +134,17 @@ class AuditItem:
|
|
|
130
134
|
advice: str
|
|
131
135
|
message: str
|
|
132
136
|
ids: List[int] = field(default_factory=list)
|
|
133
|
-
count: int = 0
|
|
137
|
+
count: int = 0 # messages
|
|
138
|
+
startups: int = 0 # distinct startups that reported it
|
|
134
139
|
last_seen: Optional[datetime] = None
|
|
140
|
+
changes: List[str] = field(default_factory=list) # "file: now -> want"
|
|
141
|
+
_seen_in: set = field(default_factory=set, repr=False)
|
|
135
142
|
|
|
136
143
|
def to_dict(self) -> dict:
|
|
137
144
|
return {"key": self.key, "severity": self.severity, "title": self.title,
|
|
138
145
|
"advice": self.advice, "message": self.message,
|
|
139
146
|
"ids": self.ids, "count": self.count,
|
|
147
|
+
"startups": self.startups, "changes": self.changes,
|
|
140
148
|
"lastSeen": self.last_seen.isoformat() if self.last_seen else None}
|
|
141
149
|
|
|
142
150
|
|
|
@@ -167,6 +175,23 @@ def _full_text(entry: LogEntry) -> str:
|
|
|
167
175
|
return entry.msg + (" [%s]" % ", ".join(details) if details else "")
|
|
168
176
|
|
|
169
177
|
|
|
178
|
+
def _change_of(entry: LogEntry) -> str:
|
|
179
|
+
"""The concrete fix a kernel-setting warning asks for, e.g.
|
|
180
|
+
"/sys/kernel/mm/transparent_hugepage/enabled: never -> always"."""
|
|
181
|
+
a = entry.attr
|
|
182
|
+
target = text(a.get("sysfsFile") or a.get("file"))
|
|
183
|
+
if not target:
|
|
184
|
+
return ""
|
|
185
|
+
now = a.get("currentValue")
|
|
186
|
+
want = a.get("desiredValue")
|
|
187
|
+
if want is None and "max_ptes_none" in target:
|
|
188
|
+
want = 0 # 8640302 says "should be 0" in its message text
|
|
189
|
+
out = "%s: %s" % (target, now if now is not None else "?")
|
|
190
|
+
if want is not None:
|
|
191
|
+
out += " -> %s" % want
|
|
192
|
+
return out
|
|
193
|
+
|
|
194
|
+
|
|
170
195
|
def audit_entries(entries: Iterable[LogEntry], source: str = "") -> AuditResult:
|
|
171
196
|
found: Dict[str, AuditItem] = {}
|
|
172
197
|
startups = 0
|
|
@@ -202,6 +227,12 @@ def audit_entries(entries: Iterable[LogEntry], source: str = "") -> AuditResult:
|
|
|
202
227
|
item = found[key] = AuditItem(key, sev, title, advice,
|
|
203
228
|
msg_text[:300])
|
|
204
229
|
item.count += 1
|
|
230
|
+
change = _change_of(entry)
|
|
231
|
+
if change and change not in item.changes:
|
|
232
|
+
item.changes.append(change)
|
|
233
|
+
if startups not in item._seen_in:
|
|
234
|
+
item._seen_in.add(startups)
|
|
235
|
+
item.startups += 1
|
|
205
236
|
if entry.msg_id and entry.msg_id not in item.ids:
|
|
206
237
|
item.ids.append(entry.msg_id)
|
|
207
238
|
if entry.ts is not None:
|
|
@@ -407,7 +407,8 @@ def cmd_ftdc(args) -> int:
|
|
|
407
407
|
"values": v.values}
|
|
408
408
|
for k, v in reader.series.items()}))
|
|
409
409
|
else:
|
|
410
|
-
print(render_ftdc_timeline(reader, args.step
|
|
410
|
+
print(render_ftdc_timeline(reader, args.step,
|
|
411
|
+
show_internal=bool(args.metric)))
|
|
411
412
|
else: # export
|
|
412
413
|
import csv as _csv
|
|
413
414
|
labels = sorted(reader.series)
|