From 5b30b95b3f74f03d96c46d7f8d521329fcb8750f Mon Sep 17 00:00:00 2001 From: ZuperZee Date: Wed, 8 Jan 2025 15:14:33 +0100 Subject: [PATCH] chore: add grafana provisioning content --- provisioning/dashboards/default.yaml | 7 + provisioning/dashboards/dyn-height-width.json | 121 ++++++++++++++ .../dashboards/update-grafana-variable.json | 154 ++++++++++++++++++ provisioning/datasources/datasources.yml | 7 + 4 files changed, 289 insertions(+) create mode 100644 provisioning/dashboards/default.yaml create mode 100644 provisioning/dashboards/dyn-height-width.json create mode 100644 provisioning/dashboards/update-grafana-variable.json create mode 100644 provisioning/datasources/datasources.yml diff --git a/provisioning/dashboards/default.yaml b/provisioning/dashboards/default.yaml new file mode 100644 index 0000000..bc20282 --- /dev/null +++ b/provisioning/dashboards/default.yaml @@ -0,0 +1,7 @@ +apiVersion: 1 + +providers: + - name: 'htmlgraphics' + type: file + options: + path: /etc/grafana/provisioning/dashboards diff --git a/provisioning/dashboards/dyn-height-width.json b/provisioning/dashboards/dyn-height-width.json new file mode 100644 index 0000000..2fdae5e --- /dev/null +++ b/provisioning/dashboards/dyn-height-width.json @@ -0,0 +1,121 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "gnetId": null, + "graphTooltip": 0, + "id": 2, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": null, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "SVGBaseFix": true, + "add100Percentage": true, + "calcsMutation": "standard", + "centerAlignContent": true, + "codeData": "{\n \"text\": \"Random text\"\n}", + "css": "* {\n font-family: Open Sans;\n}\n\ndiv {\n text-align: center;\n}", + "dynamicData": false, + "dynamicFieldDisplayValues": false, + "dynamicHtmlGraphics": false, + "dynamicProps": false, + "html": "
\n

Height:

\n

Width:

\n
\n", + "onInit": "// REMEMBER TO TURN DYNAMIC HTMLGRAPHICS AND TRIGGER ONINIT ON RESIZE TO TRUE\n\nconst [heightValueElt, widthValueElt] = htmlNode.querySelectorAll(\".value-field\");\n\nconst updateValueText = () => {\n heightValueElt.textContent = htmlGraphics.height;\n widthValueElt.textContent = htmlGraphics.width;\n}\n\nupdateValueText();\n\n", + "onInitOnResize": true, + "onRender": "", + "overflow": "visible", + "panelupdateOnMount": true, + "reduceOptions": { + "calcs": [ + "lastNotNull", + "last", + "first", + "firstNotNull", + "min", + "max", + "mean", + "sum", + "count", + "range", + "delta", + "step", + "diff", + "logmin", + "allIsZero", + "allIsNull", + "diffperc" + ] + }, + "renderOnMount": true, + "rootCSS": "", + "useGrafanaScrollbar": true + }, + "title": "Panel Title", + "type": "gapit-htmlgraphics-panel" + } + ], + "schemaVersion": 31, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Dynamic height and width", + "uid": "eSuyonDHk", + "version": 1 +} \ No newline at end of file diff --git a/provisioning/dashboards/update-grafana-variable.json b/provisioning/dashboards/update-grafana-variable.json new file mode 100644 index 0000000..a3f9ada --- /dev/null +++ b/provisioning/dashboards/update-grafana-variable.json @@ -0,0 +1,154 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "gnetId": null, + "graphTooltip": 0, + "id": 2, + "iteration": 1736334492953, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": null, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "SVGBaseFix": true, + "add100Percentage": true, + "calcsMutation": "standard", + "centerAlignContent": true, + "codeData": "{\n \"testVariable\": \"${testVariable}\"\n}", + "css": "", + "dynamicData": false, + "dynamicFieldDisplayValues": false, + "dynamicHtmlGraphics": false, + "dynamicProps": false, + "html": "\n", + "onInit": "// For Grafana v8.3.0+ the variable needs to be wrapped in ${}\nconst { testVariable } = customProperties;\nconst testVariableName = testVariable.replace(/[${}]/g, \"\");\nconst buttonElt = htmlNode.querySelector('button');\n\n/*\n Update a grafana variable\n\n More information in the grafana docs\n https://grafana.com/docs/grafana/v9.1/developers/plugins/add-support-for-variables/\n*/\nfunction updateGrafanaVariable(variableName, value) {\n getLocationSrv().update({\n query: {\n [`var-${variableName}`]: value,\n },\n partial: true, // partial: true makes the update only affect the query parameters listed in query, and leaves the other query parameters unchanged.\n replace: true, // replace: true tells Grafana to update the current URL state, rather than creating a new history entry.\n });\n}\n\nfunction getGrafanaVariableValue(variable) {\n return getTemplateSrv().replace(variable);\n}\n\nfunction updateButtonText() {\n buttonElt.textContent = `${testVariableName}'s current value is: ${getGrafanaVariableValue(testVariable)}`;\n}\n\nbuttonElt.onclick = function () {\n updateGrafanaVariable(testVariableName, getGrafanaVariableValue(testVariable) == 'b' ? 'a' : 'b');\n};\n\n/*\n When the variable changes panelupdate will trigger.\n The panelupdate is used to update the button text so the text is the same as the variable.\n*/\nhtmlNode.addEventListener('panelupdate', () => {\n updateButtonText();\n});\n", + "onInitOnResize": false, + "onRender": "", + "overflow": "visible", + "panelupdateOnMount": true, + "reduceOptions": { + "calcs": [ + "lastNotNull", + "last", + "first", + "firstNotNull", + "min", + "max", + "mean", + "sum", + "count", + "range", + "delta", + "step", + "diff", + "logmin", + "allIsZero", + "allIsNull", + "diffperc" + ] + }, + "renderOnMount": true, + "rootCSS": "", + "useGrafanaScrollbar": true + }, + "title": "Panel Title", + "type": "gapit-htmlgraphics-panel" + } + ], + "schemaVersion": 31, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "allValue": null, + "current": { + "selected": true, + "text": "b", + "value": "b" + }, + "description": null, + "error": null, + "hide": 0, + "includeAll": false, + "label": null, + "multi": false, + "name": "testVariable", + "options": [ + { + "selected": false, + "text": "a", + "value": "a" + }, + { + "selected": true, + "text": "b", + "value": "b" + } + ], + "query": "a,b", + "queryValue": "", + "skipUrlSync": false, + "type": "custom" + } + ] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Update grafana variable", + "uid": "uVluJnDHk", + "version": 1 +} diff --git a/provisioning/datasources/datasources.yml b/provisioning/datasources/datasources.yml new file mode 100644 index 0000000..9f225e6 --- /dev/null +++ b/provisioning/datasources/datasources.yml @@ -0,0 +1,7 @@ +apiVersion: 1 + +datasources: + - name: TestData DB + type: testdata + uid: trlxrdZVk + isDefault: true