From 15f0317fbe98074bddaedeaffbeb65ecde1f5621 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Thu, 7 Jul 2022 19:00:36 +0200 Subject: [PATCH] massive flux performance increase --- bundles/grafana/items.py | 2 +- data/grafana/flux.mako | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/grafana/items.py b/bundles/grafana/items.py index ddf188a..00474b0 100644 --- a/bundles/grafana/items.py +++ b/bundles/grafana/items.py @@ -142,7 +142,7 @@ for dashboard_id, monitored_node in enumerate(monitored_nodes, start=1): host=monitored_node.name, negative=query_config.get('negative', False), boolean_to_int=query_config.get('boolean_to_int', False), - resolution=query_config.get('resolution', 1) * 4, + resolution=query_config.get('resolution', 1), minimum=query_config.get('minimum', None), filters={ 'host': monitored_node.name, diff --git a/data/grafana/flux.mako b/data/grafana/flux.mako index 73ffd05..c14f03f 100644 --- a/data/grafana/flux.mako +++ b/data/grafana/flux.mako @@ -4,6 +4,7 @@ from(bucket: "${bucket}") <% values = values if isinstance(values, list) else [values] %>\ |> filter(fn: (r) => ${' or '.join(f'r["{key}"] == "{value}"' for value in values)}) % endfor + |> aggregateWindow(every: duration(v: int(v: v.windowPeriod)*${resolution}), fn: mean, createEmpty: false) // aggregate early for best performance % if minimum: |> filter(fn: (r) => r._value > ${minimum}) % endif @@ -13,7 +14,6 @@ from(bucket: "${bucket}") % if boolean_to_int: |> map(fn: (r) => ({r with _value: if r._value == true then 1 else 0 })) % endif - |> aggregateWindow(every: duration(v: int(v: v.windowPeriod)*${resolution}), fn: mean, createEmpty: false) % if negative: |> map(fn: (r) => ({r with _value: r._value * - 1.0})) % endif