From 5433925fd5d942bd1c9279854f7a05cc952e6731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sat, 2 Oct 2021 14:47:19 +0200 Subject: [PATCH] grafana: Provision first simple dashboard --- roles/grafana/files/dashboard.json | 135 +++++++++++++++++++++++++++++ roles/grafana/files/dashboard.yml | 14 +++ roles/grafana/tasks/main.yml | 25 +++++- 3 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 roles/grafana/files/dashboard.json create mode 100644 roles/grafana/files/dashboard.yml diff --git a/roles/grafana/files/dashboard.json b/roles/grafana/files/dashboard.json new file mode 100644 index 0000000..10c4c13 --- /dev/null +++ b/roles/grafana/files/dashboard.json @@ -0,0 +1,135 @@ +{ + "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, + "gnetId": null, + "graphTooltip": 0, + "id": null, + "iteration": 1633177249131, + "links": [], + "panels": [ + { + "datasource": "Prometheus", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "decimals": 0, + "mappings": [], + "max": 100, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "#98971a", + "value": null + }, + { + "color": "#d65d0e", + "value": 80 + }, + { + "color": "#cc241d", + "value": 90 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 3, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "text": {} + }, + "pluginVersion": "8.1.5", + "targets": [ + { + "exemplar": true, + "expr": "100 - (100 * node_memory_MemAvailable_bytes{instance=\"$node\"} / node_memory_MemTotal_bytes{instance=\"$node\"})", + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "title": "RAM Usage", + "type": "gauge" + } + ], + "schemaVersion": 30, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "allValue": null, + "current": { + "selected": true, + "text": "xenrox.net", + "value": "xenrox.net" + }, + "datasource": "Prometheus", + "definition": "label_values(instance)", + "description": null, + "error": null, + "hide": 0, + "includeAll": false, + "label": "Server:", + "multi": false, + "name": "node", + "options": [], + "query": { + "query": "label_values(instance)", + "refId": "StandardVariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 2, + "type": "query" + } + ] + }, + "time": { + "from": "now-24h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "Monitoring", + "uid": "UkJ1FRD7k", + "version": 0 +} diff --git a/roles/grafana/files/dashboard.yml b/roles/grafana/files/dashboard.yml new file mode 100644 index 0000000..7ed643b --- /dev/null +++ b/roles/grafana/files/dashboard.yml @@ -0,0 +1,14 @@ +apiVersion: 1 + +providers: + - name: "dashboards" + orgId: 1 + folder: "" + folderUid: "" + type: file + disableDeletion: false + updateIntervalSeconds: 10 + allowUiUpdates: false + options: + path: /var/lib/grafana/dashboards + foldersFromFilesStructure: true diff --git a/roles/grafana/tasks/main.yml b/roles/grafana/tasks/main.yml index 77fb9d3..d2d5beb 100644 --- a/roles/grafana/tasks/main.yml +++ b/roles/grafana/tasks/main.yml @@ -20,13 +20,15 @@ - name: Create provisioning directories ansible.builtin.file: state: directory - path: "/etc/grafana/{{ item }}" + path: "{{ item }}" owner: grafana group: grafana mode: 0700 with_items: - - provisioning - - provisioning/datasources + - /etc/grafana/provisioning + - /etc/grafana/provisioning/dashboards + - /etc/grafana/provisioning/datasources + - /var/lib/grafana/dashboards - name: Configure prometheus datasource ansible.builtin.copy: @@ -37,6 +39,23 @@ mode: 0600 notify: Restart grafana +- name: Configure dashboard provisioning + ansible.builtin.copy: + src: dashboard.yml + dest: /etc/grafana/provisioning/dashboards/dashboard.yml + owner: grafana + group: grafana + mode: 0600 + notify: Restart grafana + +- name: Install dashboard + ansible.builtin.copy: + src: dashboard.json + dest: /var/lib/grafana/dashboards + owner: grafana + group: grafana + mode: 0600 + - name: Start and enable ansible.builtin.systemd: name: grafana -- 2.44.0