diff --git a/grafana-dashboards/Makefile b/grafana-dashboards/Makefile new file mode 100644 index 0000000..2bbe17b --- /dev/null +++ b/grafana-dashboards/Makefile @@ -0,0 +1,13 @@ +# Generate json dashboards + +TARGETS= pergamon.filesystem.sizes.json pergamon.cpu.usage.json \ + pergamon.uptime.json pergamon.loadavg.json \ + pergamon.memory.usage.json + +default: $(TARGETS) + +%.json: %.py + generate-dashboard -o $@ $< + +clean: + rm $(TARGETS) diff --git a/grafana-dashboards/README.txt b/grafana-dashboards/README.txt new file mode 100644 index 0000000..1ea3fd4 --- /dev/null +++ b/grafana-dashboards/README.txt @@ -0,0 +1,25 @@ +Task: Grafana dashboards +======================== + +Goal: replace munin graphs + + +1. Grafanalib installation +-------------------------- + + pip3 install --user grafanalib + export PATH=$PATH:~/.local/bin + + +2. Define grafana graph programmaticaly +--------------------------------------- + +Grafanalib invocation: + + generate-dashboard -o frontend.json frontend.dashboard.py + + +3. Import dashboard into Grafana +-------------------------------- + + Cross on top of the left panel => "Import" diff --git a/grafana-dashboards/pergamon.cpu.usage.py b/grafana-dashboards/pergamon.cpu.usage.py new file mode 100644 index 0000000..b8f9922 --- /dev/null +++ b/grafana-dashboards/pergamon.cpu.usage.py @@ -0,0 +1,73 @@ +from grafanalib.core import * + +def cpu_usage_graph(cpu=0, time_from=None): + if time_from is not None: + timeFrom = "%s" % (time_from,) + else: + timeFrom = None + return Graph( + title='CPU %s usage' % (cpu,), + dataSource="Prometheus", + timeFrom=timeFrom, + stack=True, + percentage=True, + targets=[ + Target( + expr='irate(node_cpu_seconds_total{instance="192.168.100.29:9100",cpu="%s",mode="system"}[5m])' % (cpu), + legendFormat="system time", + refId='A', + ), + Target( + expr='irate(node_cpu_seconds_total{instance="192.168.100.29:9100",cpu="%s",mode="irq"}[5m])' % (cpu), + legendFormat="irq", + refId='B', + ), + Target( + expr='irate(node_cpu_seconds_total{instance="192.168.100.29:9100",cpu="%s",mode="softirq"}[5m])' % (cpu), + legendFormat="softirq", + refId='C', + ), + Target( + expr='irate(node_cpu_seconds_total{instance="192.168.100.29:9100",cpu="%s",mode="user"}[5m])' % (cpu), + legendFormat="user time", + refId='D', + ), + Target( + expr='irate(node_cpu_seconds_total{instance="192.168.100.29:9100",cpu="%s",mode="nice"}[5m])' % (cpu), + legendFormat="nice", + refId='E', + ), + Target( + expr='irate(node_cpu_seconds_total{instance="192.168.100.29:9100",cpu="%s",mode="idle"}[5m])' % (cpu), + legendFormat="idle", + refId='F', + ), + Target( + expr='irate(node_cpu_seconds_total{instance="192.168.100.29:9100",cpu="%s",mode="iowait"}[5m])' % (cpu), + legendFormat="iowait", + refId='G', + ), + Target( + expr='irate(node_cpu_seconds_total{instance="192.168.100.29:9100",cpu="%s",mode="steal"}[5m])' % (cpu), + legendFormat="steal", + refId='H', + ), + ], + yAxes=[ + YAxis(format='percentunit'), + YAxis(format=SHORT_FORMAT), + ], + ) + +dashboard = Dashboard( + title="Pergamon CPU usage auto-generated", + rows=[ + Row( + title = 'CPU 0', + panels=[ cpu_usage_graph('0'), cpu_usage_graph('0', "1y"), ], + ), + Row( + title = 'CPU 1', + panels=[ cpu_usage_graph('1'), cpu_usage_graph('1', "1y"), ], + ), + ],).auto_panel_ids() diff --git a/grafana-dashboards/pergamon.filesystem.sizes.py b/grafana-dashboards/pergamon.filesystem.sizes.py new file mode 100644 index 0000000..df8ef3b --- /dev/null +++ b/grafana-dashboards/pergamon.filesystem.sizes.py @@ -0,0 +1,55 @@ +from grafanalib.core import * + +def filesystem_graph(mountpoint, time_from=None): + if time_from is not None: + timeFrom = "%s" % (time_from,) + else: + timeFrom = None + return Graph( + title='Size of %s' % (mountpoint,), + dataSource="Prometheus", + timeFrom=timeFrom, + targets=[ + Target( + expr='node_filesystem_size_bytes{instance="192.168.100.29:9100",mountpoint="%s"}' % (mountpoint), + legendFormat="Filesystem size", + refId='A', + ), + Target( + expr='node_filesystem_size_bytes{instance="192.168.100.29:9100",mountpoint="%s"} - \ + node_filesystem_avail_bytes{instance="192.168.100.29:9100",mountpoint="%s"}' % (mountpoint, mountpoint), + legendFormat="Used space", + refId='B', + ), + ], + yAxes=[ + YAxis(format='decbytes'), + YAxis(format=SHORT_FORMAT), + ], + ) + +dashboard = Dashboard( + title="Pergamon filesystem sizes auto-generated", + templating=Templating(list=[ + Template( + name="filesystem", + label="", + query='node_filesystem_size_bytes{instance="192.168.100.29:9100"}', + regex='/mountpoint=\"(.*)\"/', + dataSource='Prometheus', + includeAll=True, + default="All", + hide = 2, + ), + ]), + rows=[ + Row( + title = '$filesystem', + panels=[ + filesystem_graph('$filesystem'), + filesystem_graph('$filesystem', "1y"), + ], + repeat = 'filesystem', + ), + ],).auto_panel_ids() + diff --git a/grafana-dashboards/pergamon.loadavg.py b/grafana-dashboards/pergamon.loadavg.py new file mode 100644 index 0000000..03c0e14 --- /dev/null +++ b/grafana-dashboards/pergamon.loadavg.py @@ -0,0 +1,32 @@ +from grafanalib.core import * + +def loadavg_graph(time_from=None): + if time_from is not None: + timeFrom = "%s" % (time_from,) + else: + timeFrom = None + return Graph( + title='Load average', + dataSource="Prometheus", + timeFrom=timeFrom, + targets=[ + Target( + expr='node_load5{instance="192.168.100.29:9100"}', + legendFormat="5m load average", + refId='A', + ), + ], + yAxes=[ + YAxis(format=SHORT_FORMAT), + YAxis(format=SHORT_FORMAT), + ], + ) + +dashboard = Dashboard( + title="Pergamon loadavg auto-generated", + rows=[ + Row( + title = 'Load average', + panels=[ loadavg_graph(), loadavg_graph("1y"), ], + ), + ],).auto_panel_ids() diff --git a/grafana-dashboards/pergamon.memory.usage.py b/grafana-dashboards/pergamon.memory.usage.py new file mode 100644 index 0000000..3aac9f9 --- /dev/null +++ b/grafana-dashboards/pergamon.memory.usage.py @@ -0,0 +1,58 @@ +from grafanalib.core import * + +def memory_graph(time_from=None): + if time_from is not None: + timeFrom = "%s" % (time_from,) + else: + timeFrom = None + return Graph( + title='Memory usage', + dataSource="Prometheus", + timeFrom=timeFrom, + stack=True, + tooltip=Tooltip(valueType=INDIVIDUAL), + targets=[ + Target( + expr='node_memory_MemTotal_bytes{instance="192.168.100.29:9100"}', + legendFormat="Total memory", + refId='A', + ), + Target( + expr='node_memory_MemTotal_bytes{instance="192.168.100.29:9100"} - \ + node_memory_MemAvailable_bytes{instance="192.168.100.29:9100"}', + legendFormat="Used memory", + refId='B', + ), + Target( + expr='node_memory_Cached_bytes{instance="192.168.100.29:9100"}', + legendFormat="File cache", + refId='C', + ), + Target( + expr='node_memory_SwapTotal_bytes{instance="192.168.100.29:9100"} - \ + node_memory_SwapFree_bytes{instance="192.168.100.29:9100"}', + legendFormat="Used swap", + refId='D', + ), + ], + seriesOverrides = [ + {"alias": "Total memory", "stack": "false"}, + {"alias": "Used swap", "stack": "false", "fill": "10"}, + ], + yAxes=[ + YAxis(format='decbytes'), + YAxis(format=SHORT_FORMAT), + ], + ) + +dashboard = Dashboard( + title="Pergamon memory usage auto-generated", + rows=[ + Row( + title = 'Memory', + panels=[ + memory_graph(), + memory_graph("1y"), + ], + ), + ],).auto_panel_ids() diff --git a/grafana-dashboards/pergamon.uptime.py b/grafana-dashboards/pergamon.uptime.py new file mode 100644 index 0000000..46dd64c --- /dev/null +++ b/grafana-dashboards/pergamon.uptime.py @@ -0,0 +1,36 @@ +from grafanalib.core import * + +def cpu_usage_graph(cpu=0, time_from=None): + if time_from is not None: + timeFrom = "%s" % (time_from,) + else: + timeFrom = None + return Graph( + title='Uptime', + dataSource="Prometheus", + timeFrom=timeFrom, + targets=[ + Target( + expr='time() - node_boot_time_seconds{instance="192.168.100.29:9100"}', + legendFormat="uptime", + refId='A', + ), + ], + yAxes=[ + YAxis(format=SECONDS_FORMAT), + YAxis(format=SHORT_FORMAT), + ], + ) + +dashboard = Dashboard( + title="Pergamon uptime auto-generated", + rows=[ + Row( + title = 'Uptime', + panels=[ + cpu_usage_graph('0'), + cpu_usage_graph('0', "1y"), + ], + repeat = 'cpu', + ), + ],).auto_panel_ids()