From 3b257aadabc48115e497ed355135e1191f91a2e2 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Fri, 12 Aug 2022 17:42:25 +0200 Subject: [PATCH] some grafana --- bundles/grafana/items.py | 18 +++--- bundles/telegraf/metadata.py | 1 - data/grafana/rows/cpu.py | 44 +++++++++++++- data/grafana/rows/disk_io.py | 6 +- data/grafana/rows/net_io.py | 6 +- data/grafana/rows/pressure_stall.py | 90 ----------------------------- 6 files changed, 61 insertions(+), 104 deletions(-) delete mode 100644 data/grafana/rows/pressure_stall.py diff --git a/bundles/grafana/items.py b/bundles/grafana/items.py index b4a1b5e..2c3717c 100644 --- a/bundles/grafana/items.py +++ b/bundles/grafana/items.py @@ -101,11 +101,11 @@ for dashboard_id, monitored_node in enumerate(monitored_nodes, start=1): dashboard['title'] = monitored_node.name dashboard['uid'] = monitored_node.metadata.get('id') panel_id = count(start=1) - + for row_id, row_name in enumerate(sorted(monitored_node.metadata.get('grafana_rows')), start=1): with open(repo.path.join([f'data/grafana/rows/{row_name}.py'])) as file: row = eval(file.read()) - + for panel_in_row, (panel_name, panel_config) in enumerate(row.items()): panel = deepcopy(panel_template) panel['id'] = next(panel_id) @@ -113,7 +113,7 @@ for dashboard_id, monitored_node in enumerate(monitored_nodes, start=1): panel['gridPos']['w'] = 24 // len(row) panel['gridPos']['x'] = (24 // len(row)) * panel_in_row panel['gridPos']['y'] = (row_id - 1) * panel['gridPos']['h'] - + if 'display_name' in panel_config: panel['fieldConfig']['defaults']['displayName'] = '${'+panel_config['display_name']+'}' @@ -127,13 +127,17 @@ for dashboard_id, monitored_node in enumerate(monitored_nodes, start=1): panel['fieldConfig']['defaults']['min'] = panel_config['min'] if 'max' in panel_config: panel['fieldConfig']['defaults']['max'] = panel_config['max'] + if 'soft_max' in panel_config: + panel['fieldConfig']['defaults']['custom']['axisSoftMax'] = panel_config['soft_max'] if 'legend' in panel_config: panel['options']['legend'].update(panel_config['legend']) if 'tooltip' in panel_config: panel['options']['tooltip']['mode'] = panel_config['tooltip'] - + if panel_config['tooltip'] == 'multi': + panel['options']['tooltip']['sort'] = 'desc' + for query_name, query_config in panel_config['queries'].items(): panel['targets'].append({ 'refId': query_name, @@ -150,13 +154,13 @@ for dashboard_id, monitored_node in enumerate(monitored_nodes, start=1): function=query_config.get('function', None), ).strip() }) - + dashboard['panels'].append(panel) - + files[f'/var/lib/grafana/dashboards/{monitored_node.name}.json'] = { 'content': json.dumps(dashboard, indent=4), 'triggers': [ 'svc_systemd:grafana-server:restart', ] } - + diff --git a/bundles/telegraf/metadata.py b/bundles/telegraf/metadata.py index 53da377..1a25d11 100644 --- a/bundles/telegraf/metadata.py +++ b/bundles/telegraf/metadata.py @@ -80,7 +80,6 @@ defaults = { 'proc_cpu', 'proc_ram', 'proc_io', - 'pressure_stall', }, 'sudoers': { 'telegraf': {'/usr/local/share/telegraf/procio'}, diff --git a/data/grafana/rows/cpu.py b/data/grafana/rows/cpu.py index 6363e38..4c7a164 100644 --- a/data/grafana/rows/cpu.py +++ b/data/grafana/rows/cpu.py @@ -1,6 +1,6 @@ { 'usage': { - 'stacked': False, + 'stacked': True, 'queries': { 'usage': { 'filters': { @@ -22,7 +22,12 @@ }, }, 'min': 0, - 'max': 100, + 'soft_max': 3, + 'unit': 'percent', + 'tooltip': 'multi', + 'legend': { + 'displayMode': 'hidden', + }, }, 'load': { 'stacked': False, @@ -39,5 +44,40 @@ 'function': 'mean', }, }, + 'min': 0, + 'soft_max': 3, + 'unit': 'percent', + 'tooltip': 'multi', + 'legend': { + 'displayMode': 'hidden', + }, + }, + 'pressure_stall': { + 'queries': { + 'pressure_stall': { + 'filters': { + '_measurement': 'pressure_stall', + 'resource': [ + 'cpu', + 'io', + 'memory', + ], + 'type': [ + 'some', + ], + '_field': [ + 'avg10', + ], + }, + }, + }, + 'min': 0, + 'soft_max': 3, + 'display_name': '__field.labels.resource', + 'unit': 'percent', + 'tooltip': 'multi', + 'legend': { + 'displayMode': 'hidden', + }, }, } diff --git a/data/grafana/rows/disk_io.py b/data/grafana/rows/disk_io.py index deca33d..6cecfd9 100644 --- a/data/grafana/rows/disk_io.py +++ b/data/grafana/rows/disk_io.py @@ -13,7 +13,8 @@ }, }, 'unit': 'decbytes', - 'display_name': '__field.labels.name' + 'display_name': '__field.labels.name', + 'tooltip': 'multi', }, 'write': { 'stacked': True, @@ -29,6 +30,7 @@ }, }, 'unit': 'decbytes', - 'display_name': '__field.labels.name' + 'display_name': '__field.labels.name', + 'tooltip': 'multi', }, } diff --git a/data/grafana/rows/net_io.py b/data/grafana/rows/net_io.py index cb8fc63..aa6b47a 100644 --- a/data/grafana/rows/net_io.py +++ b/data/grafana/rows/net_io.py @@ -13,7 +13,8 @@ }, }, 'unit': 'decbytes', - 'display_name': '__field.labels.interface' + 'display_name': '__field.labels.interface', + 'tooltip': 'multi', }, 'out': { 'stacked': True, @@ -29,6 +30,7 @@ }, }, 'unit': 'decbytes', - 'display_name': '__field.labels.interface' + 'display_name': '__field.labels.interface', + 'tooltip': 'multi', }, } diff --git a/data/grafana/rows/pressure_stall.py b/data/grafana/rows/pressure_stall.py deleted file mode 100644 index df445f5..0000000 --- a/data/grafana/rows/pressure_stall.py +++ /dev/null @@ -1,90 +0,0 @@ -{ - 'cpu': { - 'queries': { - 'seome': { - 'filters': { - '_measurement': 'pressure_stall', - 'resource': [ - 'cpu', - ], - 'type': [ - 'some', - ], - '_field': [ - 'avg10', - ], - }, - }, - }, - 'display_name': '__field.labels.type', - 'unit': 'percent', - }, - 'memory': { - 'queries': { - 'some': { - 'filters': { - '_measurement': 'pressure_stall', - 'resource': [ - 'memory', - ], - 'type': [ - 'some', - ], - '_field': [ - 'avg10', - ], - }, - }, - 'full': { - 'filters': { - '_measurement': 'pressure_stall', - 'resource': [ - 'memory', - ], - 'type': [ - 'full', - ], - '_field': [ - 'avg10', - ], - }, - }, - }, - 'display_name': '__field.labels.type', - 'unit': 'percent', - }, - 'io': { - 'queries': { - 'some': { - 'filters': { - '_measurement': 'pressure_stall', - 'resource': [ - 'io', - ], - 'type': [ - 'some', - ], - '_field': [ - 'avg10', - ], - }, - }, - 'full': { - 'filters': { - '_measurement': 'pressure_stall', - 'resource': [ - 'io', - ], - 'type': [ - 'full', - ], - '_field': [ - 'avg10', - ], - }, - }, - }, - 'display_name': '__field.labels.type', - 'unit': 'percent', - }, -}