This commit is contained in:
mwiegand 2021-07-04 18:09:50 +02:00
parent 71bc767533
commit 84ecb460df
3 changed files with 6 additions and 3 deletions

View file

@ -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()
})

View file

@ -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
}

View file

@ -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")