diff --git a/roles/serveur_grafana/defaults/main.yml b/roles/serveur_grafana/defaults/main.yml index 74c2b78..51ae3a1 100644 --- a/roles/serveur_grafana/defaults/main.yml +++ b/roles/serveur_grafana/defaults/main.yml @@ -12,6 +12,8 @@ serveur_grafana_root_url: "https://{{ serveur_grafana_hostname }}/" # Datasources (Prometheus + Loki, co-localises sur obs-01). serveur_grafana_prometheus_url: "http://localhost:9090" serveur_grafana_loki_url: "http://localhost:3100" +# Dashboards provisionnés (fichiers) — répertoire lu par le provider Grafana. +serveur_grafana_dashboards_dir: "/var/lib/grafana/dashboards" # Secret OBLIGATOIRE (Ansible Vault). serveur_grafana_admin_password: "{{ vault_grafana_admin | default('') }}" # rempli depuis la voute (vault_grafana_admin) diff --git a/roles/serveur_grafana/files/dashboards/journaux-flotte.json b/roles/serveur_grafana/files/dashboards/journaux-flotte.json new file mode 100644 index 0000000..a27f096 --- /dev/null +++ b/roles/serveur_grafana/files/dashboards/journaux-flotte.json @@ -0,0 +1,66 @@ +{ + "uid": "setops-journaux", + "title": "Journaux de la flotte", + "tags": ["set-ops", "logs"], + "timezone": "browser", + "schemaVersion": 39, + "version": 1, + "refresh": "30s", + "time": { "from": "now-1h", "to": "now" }, + "templating": { + "list": [ + { + "name": "ds_loki", + "label": "Source Loki", + "type": "datasource", + "query": "loki", + "hide": 2, + "current": {} + }, + { + "name": "host", + "label": "Hôte", + "type": "query", + "datasource": { "type": "loki", "uid": "${ds_loki}" }, + "query": "label_values(host)", + "definition": "label_values(host)", + "includeAll": true, + "multi": true, + "current": { "text": "All", "value": "$__all" }, + "refresh": 2, + "sort": 1 + }, + { + "name": "filtre", + "label": "Filtre (regex, insensible à la casse)", + "type": "textbox", + "query": "", + "current": { "text": "", "value": "" } + } + ] + }, + "panels": [ + { + "id": 1, + "type": "timeseries", + "title": "Débit des journaux (lignes/s) par hôte", + "datasource": { "type": "loki", "uid": "${ds_loki}" }, + "gridPos": { "h": 7, "w": 24, "x": 0, "y": 0 }, + "fieldConfig": { "defaults": { "custom": { "drawStyle": "bars", "fillOpacity": 40, "stacking": { "mode": "normal" } } } }, + "targets": [ + { "refId": "A", "datasource": { "type": "loki", "uid": "${ds_loki}" }, "expr": "sum by (host) (rate({host=~\"$host\"} |~ \"(?i)$filtre\" [$__interval]))", "legendFormat": "{{host}}" } + ] + }, + { + "id": 2, + "type": "logs", + "title": "Journaux", + "datasource": { "type": "loki", "uid": "${ds_loki}" }, + "gridPos": { "h": 18, "w": 24, "x": 0, "y": 7 }, + "options": { "showTime": true, "wrapLogMessage": true, "prettifyLogMessage": false, "enableLogDetails": true, "sortOrder": "Descending" }, + "targets": [ + { "refId": "A", "datasource": { "type": "loki", "uid": "${ds_loki}" }, "expr": "{host=~\"$host\"} |~ \"(?i)$filtre\"" } + ] + } + ] +} diff --git a/roles/serveur_grafana/tasks/main.yml b/roles/serveur_grafana/tasks/main.yml index b21bd84..8bb1a5f 100644 --- a/roles/serveur_grafana/tasks/main.yml +++ b/roles/serveur_grafana/tasks/main.yml @@ -42,6 +42,33 @@ mode: "0640" notify: Redemarrer grafana +- name: Assurer le repertoire des dashboards + ansible.builtin.file: + path: "{{ serveur_grafana_dashboards_dir }}" + state: directory + owner: root + group: grafana + mode: "0750" + +- name: Deployer le provisioning des dashboards + ansible.builtin.template: + src: dashboards.yaml.j2 + dest: /etc/grafana/provisioning/dashboards/setops.yaml + owner: root + group: grafana + mode: "0640" + notify: Redemarrer grafana + +- name: Deployer les dashboards Set-OPS + ansible.builtin.copy: + src: dashboards/ + dest: "{{ serveur_grafana_dashboards_dir }}/" + owner: root + group: grafana + mode: "0640" + directory_mode: "0750" + notify: Redemarrer grafana + - name: Assurer le repertoire de drop-in systemd ansible.builtin.file: path: /etc/systemd/system/grafana-server.service.d diff --git a/roles/serveur_grafana/templates/dashboards.yaml.j2 b/roles/serveur_grafana/templates/dashboards.yaml.j2 new file mode 100644 index 0000000..5a8e80d --- /dev/null +++ b/roles/serveur_grafana/templates/dashboards.yaml.j2 @@ -0,0 +1,14 @@ +# Gere par Set-OPS (role serveur_grafana). Ne pas editer a la main. +apiVersion: 1 + +providers: + - name: setops + orgId: 1 + folder: Set-OPS + type: file + disableDeletion: false + updateIntervalSeconds: 30 + allowUiUpdates: false + options: + path: {{ serveur_grafana_dashboards_dir }} + foldersFromFilesStructure: false