fix(dashboard_gen): use RATE_WINDOW in rate_per_min calculation

This commit is contained in:
Daniil Polyakov 2026-08-03 19:29:16 +03:00
parent 037901fe94
commit acb73dce0c
3 changed files with 14 additions and 8 deletions

View File

@ -71,7 +71,7 @@
"targets": [ "targets": [
{ {
"datasource": { "type": "prometheus", "uid": "prometheus" }, "datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "rate(blocks_produced_total[1m]) * 60", "expr": "rate(blocks_produced_total[$__rate_interval]) * 60",
"legendFormat": "produced · blocks/min", "legendFormat": "produced · blocks/min",
"refId": "A" "refId": "A"
} }
@ -327,19 +327,19 @@
"targets": [ "targets": [
{ {
"datasource": { "type": "prometheus", "uid": "prometheus" }, "datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "rate(submitted_transactions_total[1m]) * 60", "expr": "rate(submitted_transactions_total[$__rate_interval]) * 60",
"legendFormat": "submitted", "legendFormat": "submitted",
"refId": "A" "refId": "A"
}, },
{ {
"datasource": { "type": "prometheus", "uid": "prometheus" }, "datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "rate(before_mempool_failed_transactions_total[1m]) * 60", "expr": "rate(before_mempool_failed_transactions_total[$__rate_interval]) * 60",
"legendFormat": "failed · before mempool", "legendFormat": "failed · before mempool",
"refId": "B" "refId": "B"
}, },
{ {
"datasource": { "type": "prometheus", "uid": "prometheus" }, "datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "rate(mempool_failed_transactions_total[1m]) * 60", "expr": "rate(mempool_failed_transactions_total[$__rate_interval]) * 60",
"legendFormat": "failed · in mempool", "legendFormat": "failed · in mempool",
"refId": "C" "refId": "C"
} }

View File

@ -8,3 +8,6 @@ datasources:
url: http://prometheus:9090 url: http://prometheus:9090
isDefault: true isDefault: true
editable: true editable: true
jsonData:
# Must match prometheus.yml's `scrape_interval`
timeInterval: 5s

View File

@ -36,9 +36,10 @@ mod unit;
/// than by a per-environment URL. /// than by a per-environment URL.
pub const DATASOURCE_UID: &str = "prometheus"; pub const DATASOURCE_UID: &str = "prometheus";
/// Window every histogram query rates over. `$__rate_interval` tracks the /// Window every rate query — counter and histogram alike — rates over.
/// panel's zoom, so a percentile covers the range you are actually looking at, /// `$__rate_interval` tracks the panel's zoom, so the window always covers the
/// and an idle window yields no value rather than a zero. /// step Grafana samples at: a fixed one shorter than the step leaves gaps the
/// query never looks at, dropping events from the graph entirely.
const RATE_WINDOW: &str = "$__rate_interval"; const RATE_WINDOW: &str = "$__rate_interval";
/// Dashboard variable holding the quantile every percentile query reads. /// Dashboard variable holding the quantile every percentile query reads.
@ -578,7 +579,9 @@ pub fn avg(metric: &str) -> Target {
/// A per-minute rate target for a counter metric. /// A per-minute rate target for a counter metric.
#[must_use] #[must_use]
pub fn rate_per_min(metric: &str, legend: &str) -> Target { pub fn rate_per_min(metric: &str, legend: &str) -> Target {
Target::new(format!("rate({metric}[1m]) * 60")).legend(legend) //`rate` is per-second whatever the window, so `* 60` is per-minute regardless of the panel's
//`rate` zoom.
Target::new(format!("rate({metric}[{RATE_WINDOW}]) * 60")).legend(legend)
} }
const fn default_unit() -> Unit { const fn default_unit() -> Unit {