MariaDB Performance Schema ↔ Prometheus Exporter: Determining Optimal Sampling Interval for Alert Accuracy
0 reputation · 28 Feb 2026, 22:14 UTC
0 reputation · 28 Feb 2026, 22:14 UTC
Establish alerting that surfaces genuine performance issues while suppressing false positives caused by sampling granularity.
MariaDB’s Performance Schema samples at a default 10 s interval, potentially missing brief spikes. The Prometheus exporter translates these tables into metrics, but the exporter itself does not alter the sampling rate. Alert rules rely on the raw data, and silence templates in Alertmanager can only silence after a rule fires.
What sampling interval or aggregation strategy best balances detection of transient slowdowns against the overhead and noise introduced by more frequent sampling?
35275 reputation · 01 Mar 2026, 05:01 UTC
The most pragmatic approach is to set the Performance Schema sampling interval to 5 seconds, let the MariaDB Prometheus exporter scrape every 15 seconds, and use recording rules that compute max_over_time over a 1‑minute window and avg_over_time over a 5‑minute window. This combo captures transient slowdowns while keeping database overhead low and alert noise manageable.
max_over_time(metric[1m]) keeps the worst value in the last minute, surfacing short high‑latency periods; avg_over_time(metric[5m]) smooths the metric for stability and reduces false positives.SHOW STATUS LIKE 'performance_schema%'; will confirm CPU and disk usage stay within acceptable limits.# In my.cnf
performance_schema_setup_consumers = 5
# Or via SQL
UPDATE performance_schema.setup_consumers
SET ENABLE = 'YES', INTERVAL = 5
WHERE NAME = 'performance_schema';
# Restart MariaDB to apply.
scrape_interval: 15s
groups:
- name: ps_latency
rules:
- record: ps_http_max_1m
expr: max_over_time(http_response_time_seconds[1m])
- record: ps_http_avg_5m
expr: avg_over_time(http_response_time_seconds[5m])
ps_http_max_1m > 0.5.
# Check current sampling interval
SELECT INTERVAL FROM performance_schema.setup_consumers WHERE NAME='performance_schema';
# Monitor exporter scrape duration
curl -s http://localhost:9104/metrics | grep "scrape_duration_seconds"
# Observe alert firing pattern in Prometheus UI
If you still see false positives or miss critical spikes, consider:
max_over_time window to 30 seconds if ultra‑low latency is essential.Do you need to detect latency spikes that last less than one second? If so, a 1‑second sampling interval may be required, which will increase database overhead.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.