~xenrox/ansible

5433925fd5d942bd1c9279854f7a05cc952e6731 — Thorben Günther 2 years ago 201dde1
grafana: Provision first simple dashboard
A roles/grafana/files/dashboard.json => roles/grafana/files/dashboard.json +135 -0
@@ 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
}

A roles/grafana/files/dashboard.yml => roles/grafana/files/dashboard.yml +14 -0
@@ 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

M roles/grafana/tasks/main.yml => roles/grafana/tasks/main.yml +22 -3
@@ 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