From 81527ca611f4da931e4dc0387405667110f9d222 Mon Sep 17 00:00:00 2001 From: Pavan Nagaraj Date: Wed, 1 Jul 2026 20:52:45 +0530 Subject: [PATCH] feat(support-bundle): collect MongoDB per-collection sizes in infra and edge bundles Add per-database and per-collection storage/data sizes and document counts (mongo/db-collection-sizes.txt) to both the infra and edge support bundles, via listDatabases + db.stats()/collection.stats(). This surfaces WHICH collections consume disk (events, audits, metrics, cluster summaries, etc.), the recurring "what is eating MongoDB storage" triage question. Follow-up to the per-pod df collection; motivated by SCS-4625 / SUS-1801. Co-Authored-By: Claude Opus 4.8 (1M context) --- support-bundle/README-edge.md | 1 + support-bundle/README-infra.md | 1 + support-bundle/support-bundle-edge.sh | 11 +++++++++++ support-bundle/support-bundle-infra.sh | 11 +++++++++++ 4 files changed, 24 insertions(+) diff --git a/support-bundle/README-edge.md b/support-bundle/README-edge.md index f1e4d9b..b2cde48 100644 --- a/support-bundle/README-edge.md +++ b/support-bundle/README-edge.md @@ -207,3 +207,4 @@ For Enterprise and PCG clusters, the script collects MongoDB replica set informa * `rs-conf.json`: Replica set configuration including member settings and priorities * `replication-info.txt`: Oplog information and replication window * `disk-usage.txt`: Actual `df -h /var/lib/mongodb` per mongo pod — the real on-disk size, which can differ from the requested PVC/PV size on thin-provisioned or fixed-disk-offering backends (e.g. CloudStack fixed offerings) +* `db-collection-sizes.txt`: Per-database and per-collection storage/data sizes (MB) and document counts — shows which collections are consuming disk diff --git a/support-bundle/README-infra.md b/support-bundle/README-infra.md index 4941795..972219c 100644 --- a/support-bundle/README-infra.md +++ b/support-bundle/README-infra.md @@ -151,6 +151,7 @@ For Enterprise and PCG clusters, the script collects MongoDB replica set informa * `rs-conf.json`: Replica set configuration including member settings and priorities * `replication-info.txt`: Oplog information and replication window * `disk-usage.txt`: Actual `df -h /var/lib/mongodb` per mongo pod — the real on-disk size, which can differ from the requested PVC/PV size on thin-provisioned or fixed-disk-offering backends (e.g. CloudStack fixed offerings) +* `db-collection-sizes.txt`: Per-database and per-collection storage/data sizes (MB) and document counts — shows which collections are consuming disk ## Important Notes diff --git a/support-bundle/support-bundle-edge.sh b/support-bundle/support-bundle-edge.sh index 730476b..104a0c2 100755 --- a/support-bundle/support-bundle-edge.sh +++ b/support-bundle/support-bundle-edge.sh @@ -682,6 +682,17 @@ function mongo-status() { echo } >> "${TMPDIR}/mongo/disk-usage.txt" done < <(printf '%s\n' "$MONGO_PODS") + + techo "Collecting MongoDB database + collection sizes" + kubectl exec -n hubble-system "$MONGO_POD" -c mongo -- bash -c "$MONGO_CMD $MONGO_AUTH admin --quiet --eval ' + db.adminCommand({listDatabases:1}).databases.forEach(function(d){ + var s = db.getSiblingDB(d.name).stats(1024*1024); + print(\"DB \"+d.name+\" storageSize(MB)=\"+s.storageSize+\" dataSize(MB)=\"+s.dataSize); + db.getSiblingDB(d.name).getCollectionNames().forEach(function(c){ + var cs = db.getSiblingDB(d.name).getCollection(c).stats(1024*1024); + print(\" \"+d.name+\".\"+c+\" storageSize(MB)=\"+cs.storageSize+\" size(MB)=\"+cs.size+\" count=\"+cs.count); + }); + });'" > "${TMPDIR}/mongo/db-collection-sizes.txt" 2>&1 } function k8s-resources() { diff --git a/support-bundle/support-bundle-infra.sh b/support-bundle/support-bundle-infra.sh index e5d6e2e..92641c3 100755 --- a/support-bundle/support-bundle-infra.sh +++ b/support-bundle/support-bundle-infra.sh @@ -192,6 +192,17 @@ function mongo-status() { echo } >> "${TMPDIR}/mongo/disk-usage.txt" done < <(printf '%s\n' "$MONGO_PODS") + + techo "Collecting MongoDB database + collection sizes" + kubectl exec -n hubble-system "$MONGO_POD" -c mongo -- bash -c "$MONGO_CMD $MONGO_AUTH admin --quiet --eval ' + db.adminCommand({listDatabases:1}).databases.forEach(function(d){ + var s = db.getSiblingDB(d.name).stats(1024*1024); + print(\"DB \"+d.name+\" storageSize(MB)=\"+s.storageSize+\" dataSize(MB)=\"+s.dataSize); + db.getSiblingDB(d.name).getCollectionNames().forEach(function(c){ + var cs = db.getSiblingDB(d.name).getCollection(c).stats(1024*1024); + print(\" \"+d.name+\".\"+c+\" storageSize(MB)=\"+cs.storageSize+\" size(MB)=\"+cs.size+\" count=\"+cs.count); + }); + });'" > "${TMPDIR}/mongo/db-collection-sizes.txt" 2>&1 } function k8s-resources() {