From 9b9465502af9642874105f2002e351c040cad6d5 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sun, 2 May 2021 11:55:34 +0200 Subject: [PATCH] bundles/grafana: add postfix graph --- bundles/grafana/dashboard-rows/postfix.py | 128 ++++++++++++++++++++++ bundles/grafana/items.py | 4 + 2 files changed, 132 insertions(+) create mode 100644 bundles/grafana/dashboard-rows/postfix.py diff --git a/bundles/grafana/dashboard-rows/postfix.py b/bundles/grafana/dashboard-rows/postfix.py new file mode 100644 index 0000000..e1a186e --- /dev/null +++ b/bundles/grafana/dashboard-rows/postfix.py @@ -0,0 +1,128 @@ +def dashboard_row_postfix(panel_id, node): + queries = [] + + for measurement in [ + 'active', + 'corrupt', + 'deferred', + 'hold', + 'incoming', + ]: + queries.append({ + 'groupBy': [ + {'type': 'time', 'params': ['$__interval']}, + {'type': 'fill', 'params': ['linear']}, + ], + 'orderByTime': "ASC", + 'policy': "default", + 'query': f"""from(bucket: "telegraf") + |> range(start: v.timeRangeStart, stop: v.timeRangeStop) + |> filter(fn: (r) => + r["_measurement"] == "postfix_queue" and + r["_field"] == "count" and + r["status"] == "{measurement}" and + r["host"] == "{node.name}" + ) + |> rename(columns: {{_field: "{measurement}"}}) + |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) + |> yield(name: "{measurement}")""", + 'resultFormat': 'time_series', + 'select': [[ + {'type': 'field', 'params': ['value']}, + {'type': 'mean', 'params': []}, + ]], + "tags": [] + }) + + return { + 'title': 'postfix', + 'collapse': False, + 'editable': False, + 'height': '200px', + 'panels': [ + { + 'aliasColors': {}, + 'bars': False, + 'dashLength': 10, + 'dashes': False, + 'datasource': None, + 'fieldConfig': { + 'defaults': { + 'displayName': '${__field.name}' + }, + 'overrides': [] + }, + 'fill': 1, + 'fillGradient': 0, + 'hiddenSeries': False, + 'id': next(panel_id), + 'legend': { + 'alignAsTable': False, + 'avg': False, + 'current': False, + 'max': False, + 'min': False, + 'rightSide': False, + 'show': True, + 'total': False, + 'values': False + }, + 'lines': True, + 'linewidth': 1, + 'NonePointMode': 'None', + 'options': { + 'alertThreshold': True + }, + 'percentage': False, + 'pluginVersion': '7.5.5', + 'pointradius': 2, + 'points': False, + 'renderer': 'flot', + 'seriesOverrides': [], + 'spaceLength': 10, + 'span': 12, + 'stack': True, + 'steppedLine': False, + 'targets': queries, + 'thresholds': [], + 'timeRegions': [], + 'title': 'postfix queue', + 'tooltip': { + 'shared': True, + 'sort': 0, + 'value_type': 'individual' + }, + 'type': 'graph', + 'xaxis': { + 'buckets': None, + 'mode': 'time', + 'name': None, + 'show': True, + 'values': [] + }, + 'yaxes': [ + { + 'format': 'short', + 'label': None, + 'logBase': 1, + 'max': None, + 'min': 0, + 'show': True, + 'decimals': 0, + }, + { + 'format': 'short', + 'label': None, + 'logBase': 1, + 'max': None, + 'min': None, + 'show': False, + } + ], + 'yaxis': { + 'align': False, + 'alignLevel': None + } + }, + ], + } diff --git a/bundles/grafana/items.py b/bundles/grafana/items.py index 26a93d9..7304e1c 100644 --- a/bundles/grafana/items.py +++ b/bundles/grafana/items.py @@ -94,6 +94,10 @@ for rnode in repo.nodes: dashboard['rows'].append(dashboard_row_nginx(panel_id, rnode)) dashboard['tags'].add('nginx') + if rnode.has_bundle('postfix'): + dashboard['rows'].append(dashboard_row_postfix(panel_id, rnode)) + dashboard['tags'].add('postfix') + files[f'/var/lib/grafana/dashboards/{rnode.name}.json'] = { # use metadata_to_json, because this supports sets 'content': metadata_to_json(dashboard),