From 504f96507132d5ec3e1364700e755977ea54deea Mon Sep 17 00:00:00 2001 From: Thomas Flament Date: Mon, 8 Jun 2026 15:34:35 +0200 Subject: [PATCH 1/2] mongodb: enable dbstatsfreestorage collector in exporter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add --collector.dbstatsfreestorage to mongodb_exporter's extraArgs so the dbstats response's freeStorageSize / indexFreeStorageSize / totalFreeStorageSize fields are surfaced as top-level Prometheus series (mongodb_dbstats_freeStorageSize{database, rs_nm, ...} etc.). These sub-collectors are not bundled into the catch-all options the exporter exposes (--collect-all and similar shortcuts); they have to be opted into explicitly. Since the chart no longer uses --collect-all anyway (dropped in 8414833 for ZENKO-5281), each individual collector we want has to be named in extraArgs — which is already how dbstats, diagnosticdata, replicasetstatus, and topmetrics are wired up. This just adds dbstatsfreestorage to that list. Verified on a live Artesca cluster (exporter 0.40.0): without this flag the freeStorageSize fields only appear as part of the per-host mongodb_dbstats_raw__freeStorageSize series — clunky for alerting queries. With the flag they appear cleanly as top-level series with {database, rs_nm, ...} labels. This unblocks the MongoDbCompactionNeeded alert added in the following commit, which needs totalFreeStorageSize at top level to express the compaction-pressure heuristic. Issue: ZENKO-5293 --- solution-base/mongodb/charts/mongodb-sharded/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution-base/mongodb/charts/mongodb-sharded/values.yaml b/solution-base/mongodb/charts/mongodb-sharded/values.yaml index 0aa3089c79..cfdfc9a2f6 100644 --- a/solution-base/mongodb/charts/mongodb-sharded/values.yaml +++ b/solution-base/mongodb/charts/mongodb-sharded/values.yaml @@ -1815,7 +1815,7 @@ metrics: ## @param metrics.extraArgs String with extra arguments to the metrics exporter ## ref: https://github.com/percona/mongodb_exporter/blob/main/main.go ## - extraArgs: "--collector.diagnosticdata --collector.replicasetstatus --collector.dbstats --collector.topmetrics --compatible-mode" + extraArgs: "--collector.diagnosticdata --collector.replicasetstatus --collector.dbstats --collector.dbstatsfreestorage --collector.topmetrics --compatible-mode" ## @param metrics.resourcesPreset Set container resources according to one common preset (allowed values: none, nano, micro, small, medium, large, xlarge, 2xlarge). This is ignored if metrics.resources is set (metrics.resources is recommended for production). ## More information: https://github.com/bitnami/charts/blob/main/bitnami/common/templates/_resources.tpl#L15 ## From b8e0edaf387ed416214bf52b22c10f79d4fbe3bf Mon Sep 17 00:00:00 2001 From: Thomas Flament Date: Mon, 8 Jun 2026 15:34:35 +0200 Subject: [PATCH 2/2] mongodb: alert when compaction is needed Add MongoDbCompactionNeeded Prometheus rule that fires when a MongoDB database has accumulated reclaimable storage exceeding 30% of the underlying filesystem capacity: totalFreeStorageSize > 0.3 * fsTotalSize for: 1h Per-(pod, database) granularity, severity warning. The threshold is exposed as the compactionFreeStorageRatioThreshold x-input. Expressing it as a fraction of fsTotalSize lets it scale across cluster sizes: a 100 GB filesystem fires around 30 GB reclaimable; a 10 TB filesystem fires around 3 TB. Companion fixture covers a needs-compaction DB and a healthy DB sharing the same filesystem (the first crosses the threshold, the second doesn't). Issue: ZENKO-5293 --- monitoring/mongodb/alerts.test.yaml | 34 +++++++++++++++++++++++++++++ monitoring/mongodb/alerts.yaml | 14 ++++++++++++ 2 files changed, 48 insertions(+) diff --git a/monitoring/mongodb/alerts.test.yaml b/monitoring/mongodb/alerts.test.yaml index ecee2cb901..dd5ca47d76 100644 --- a/monitoring/mongodb/alerts.test.yaml +++ b/monitoring/mongodb/alerts.test.yaml @@ -698,3 +698,37 @@ tests: - alertname: MongoDbCreateIndexesFailed eval_time: 16m exp_alerts: [] + + - name: MongoDbCompactionNeeded + interval: 5m + input_series: + # Compaction-needed DB: 4 GB reclaimable on a 10 GB filesystem (40% > 30%) + - series: mongodb_dbstats_fsTotalSize{namespace="zenko", pod="data-db-mongodb-sharded-shard0-data-0", database="needs-compaction"} + values: 1e10x13 + - series: mongodb_dbstats_totalFreeStorageSize{namespace="zenko", pod="data-db-mongodb-sharded-shard0-data-0", database="needs-compaction"} + values: 4e9x13 + # Healthy DB on same pod: 1 GB reclaimable on the same 10 GB filesystem (10% < 30%) + - series: mongodb_dbstats_fsTotalSize{namespace="zenko", pod="data-db-mongodb-sharded-shard0-data-0", database="healthy-db"} + values: 1e10x13 + - series: mongodb_dbstats_totalFreeStorageSize{namespace="zenko", pod="data-db-mongodb-sharded-shard0-data-0", database="healthy-db"} + values: 1e9x13 + alert_rule_test: + # for: 1h not yet satisfied + - alertname: MongoDbCompactionNeeded + eval_time: 10m + exp_alerts: [] + - alertname: MongoDbCompactionNeeded + eval_time: 55m + exp_alerts: [] + # for: 1h satisfied; only the needs-compaction DB fires + - alertname: MongoDbCompactionNeeded + eval_time: 65m + exp_alerts: + - exp_labels: + severity: warning + namespace: zenko + pod: data-db-mongodb-sharded-shard0-data-0 + database: needs-compaction + exp_annotations: + description: "MongoDB pod `data-db-mongodb-sharded-shard0-data-0` database `needs-compaction` has accumulated reclaimable storage exceeding 0.3 of the filesystem capacity. Consider running compaction to recover disk space." + summary: MongoDB compaction needed diff --git a/monitoring/mongodb/alerts.yaml b/monitoring/mongodb/alerts.yaml index 45b3ad1aef..11328cecf4 100644 --- a/monitoring/mongodb/alerts.yaml +++ b/monitoring/mongodb/alerts.yaml @@ -27,6 +27,9 @@ x-inputs: - name: replicationLagOplogSizeThreshold type: config value: 0.5 + - name: compactionFreeStorageRatioThreshold + type: config + value: 0.3 groups: - name: MongoDb @@ -280,6 +283,17 @@ groups: description: "MongoDB pod `{{ $labels.pod }}` reported failed createIndexes commands in the last 5 minutes." summary: MongoDB index creation failure + - alert: MongoDbCompactionNeeded + expr: | + mongodb_dbstats_totalFreeStorageSize{namespace="${namespace}",pod=~"${service}.*"} + > ${compactionFreeStorageRatioThreshold} * mongodb_dbstats_fsTotalSize{namespace="${namespace}",pod=~"${service}.*"} + for: 1h + labels: + severity: warning + annotations: + description: "MongoDB pod `{{ $labels.pod }}` database `{{ $labels.database }}` has accumulated reclaimable storage exceeding ${compactionFreeStorageRatioThreshold} of the filesystem capacity. Consider running compaction to recover disk space." + summary: MongoDB compaction needed + - alert: MongoDbRSNotSynced expr: | count by (rs_nm, statefulset) (