From 84ecb460df05f7817a4d46f4eb4acc46f4c11f9e Mon Sep 17 00:00:00 2001 From: mwiegand Date: Sun, 4 Jul 2021 18:09:50 +0200 Subject: [PATCH] wip --- bundles/grafana/items.py | 4 +++- data/grafana/dashboard.py | 2 +- data/grafana/flux.mako | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bundles/grafana/items.py b/bundles/grafana/items.py index 1622b73..3e37f67 100644 --- a/bundles/grafana/items.py +++ b/bundles/grafana/items.py @@ -86,6 +86,7 @@ bucket = repo.get_node(node.metadata.get('grafana/influxdb_node')).metadata.get( for dashboard_id, (node_name, panels) in enumerate(node.metadata.get('grafana/dashboards').items(), start=1): dashboard = deepcopy(dashboard_template) dashboard['id'] = dashboard_id + dashboard['title'] = node_name for panel_id, (panel_name, panel_config) in enumerate(panels.items(), start=1): panel = deepcopy(panel_template) @@ -93,13 +94,14 @@ for dashboard_id, (node_name, panels) in enumerate(node.metadata.get('grafana/da panel['title'] = panel_name for target_name, target_config in panel_config.items(): + print(target_name, target_config) panel['targets'].append({ 'refId': target_name, 'query': flux_template.render( bucket=bucket, host=node_name, field=target_name, - filters=target_config, + filters=target_config['filter'], ).strip() }) diff --git a/data/grafana/dashboard.py b/data/grafana/dashboard.py index b335b89..6a04af5 100644 --- a/data/grafana/dashboard.py +++ b/data/grafana/dashboard.py @@ -1,5 +1,6 @@ { # "id": 1, +# "title": "some dashboard", "annotations": { "list": [ { @@ -58,7 +59,6 @@ }, "timepicker": {}, "timezone": "", - "title": "New dashboard Copy", "uid": "IBPgYBznk", "version": 15 } diff --git a/data/grafana/flux.mako b/data/grafana/flux.mako index ed41df9..45ac1e9 100644 --- a/data/grafana/flux.mako +++ b/data/grafana/flux.mako @@ -2,7 +2,8 @@ from(bucket: "${bucket}") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["host"] == "${host}") % for key, value in filters.items(): - |> filter(fn: (r) => r["_field"] == "${field}") + |> filter(fn: (r) => r["${key}"] == "${value}") % endfor + |> filter(fn: (r) => r["_field"] == "${field}") |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) |> yield(name: "mean")