Merge pull request #1 from darnodo/geat/logs_exporter

Geat/logs exporter
This commit is contained in:
D. Arnodo
2025-06-25 19:34:02 +02:00
committed by GitHub
7 changed files with 245 additions and 0 deletions

View File

@@ -12,3 +12,4 @@
become: true become: true
roles: roles:
- role: dns_server - role: dns_server
- role: grafana_alloy

View File

@@ -13,3 +13,4 @@
become: true become: true
roles: roles:
- role: dns_server - role: dns_server
- role: grafana_alloy

View File

@@ -28,6 +28,9 @@ server={{ server }}
# Taille du cache # Taille du cache
cache-size={{ dnsmasq_cache_size }} cache-size={{ dnsmasq_cache_size }}
# Configuration log
log-facility=/var/log/dnsmasq.log
# On indique explicitement où trouver nos listes d'hôtes additionnelles # On indique explicitement où trouver nos listes d'hôtes additionnelles
addn-hosts=/etc/dnsmasq.hosts.d/records.home.arnodo.fr addn-hosts=/etc/dnsmasq.hosts.d/records.home.arnodo.fr
addn-hosts=/etc/dnsmasq.hosts.d/records.lab.arnodo.fr addn-hosts=/etc/dnsmasq.hosts.d/records.lab.arnodo.fr

View File

@@ -0,0 +1,24 @@
---
# ================================================================
# Handlers for grafana_alloy role
# ================================================================
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true
become: true
listen: Reload systemd
- name: Restart alloy
ansible.builtin.service:
name: alloy
state: restarted
become: true
listen: Restart alloy
- name: Convert GPG key
ansible.builtin.command:
cmd: gpg --dearmor -o /etc/apt/keyrings/grafana.gpg /tmp/grafana.gpg.key
creates: /etc/apt/keyrings/grafana.gpg
become: true
listen: Convert GPG key

View File

@@ -0,0 +1,139 @@
---
# ================================================================
# Rôle : grafana_alloy
# Tâches principales
#
# Objectif : Installer Grafana Alloy depuis le dépôt officiel
# Grafana sur une distribution Debian/Ubuntu, puis
# déployer la configuration et le service systemd.
#
# Étapes CLI équivalentes :
# 1. sudo apt install gpg
# 2. sudo mkdir -p /etc/apt/keyrings/
# 3. wget -q -O - https://apt.grafana.com/gpg.key | \
# gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg >/dev/null
# 4. echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] \
# https://apt.grafana.com stable main" \
# | sudo tee /etc/apt/sources.list.d/grafana.list
# 5. sudo apt-get update
# 6. sudo apt-get install alloy
# 7. sudo systemctl start alloy
# 8. sudo systemctl enable alloy.service
#
# Cette implémentation reprend ces étapes en Ansible et ajoute
# les déploiements de configuration + unité systemd.
# ================================================================
- name: "[grafana_alloy] Paquets de base (gpg, wget, apt-transport-https, ca-certificates)"
ansible.builtin.apt:
name:
- gpg
- wget
- apt-transport-https
- ca-certificates
state: present
update_cache: true
tags:
- grafana_alloy
- install
- name: "[grafana_alloy] Création du répertoire /etc/apt/keyrings"
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: "0755"
tags:
- grafana_alloy
- repo
- name: "[grafana_alloy] Téléchargement de la clé GPG Grafana"
ansible.builtin.get_url:
url: https://apt.grafana.com/gpg.key
dest: /tmp/grafana.gpg.key
mode: "0644"
notify: Convert GPG key
tags:
- grafana_alloy
- repo
- name: "[grafana_alloy] Conversion de la clé GPG au format keyring"
ansible.builtin.command:
cmd: gpg --dearmor -o /etc/apt/keyrings/grafana.gpg /tmp/grafana.gpg.key
creates: /etc/apt/keyrings/grafana.gpg
tags:
- grafana_alloy
- repo
- name: "[grafana_alloy] Ajout du dépôt Grafana"
ansible.builtin.apt_repository:
repo: "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main"
filename: grafana
state: present
tags:
- grafana_alloy
- repo
- name: "[grafana_alloy] Installation du paquet alloy"
ansible.builtin.apt:
name: alloy
state: present
update_cache: true
tags:
- grafana_alloy
- install
# ----------------------------------------------------------------
# Déploiement de la configuration d'Alloy (River)
# ----------------------------------------------------------------
- name: "[grafana_alloy] Dossier de configuration /etc/alloy"
ansible.builtin.file:
path: /etc/alloy
state: directory
owner: root
group: root
mode: "0755"
tags:
- grafana_alloy
- config
- name: "[grafana_alloy] Déploiement de la configuration Alloy"
ansible.builtin.template:
src: config.alloy.j2
dest: "{{ alloy_config_file | default('/etc/alloy/config.alloy') }}"
owner: root
group: root
mode: "0644"
notify:
- Restart alloy
tags:
- grafana_alloy
- config
# ----------------------------------------------------------------
# Déploiement/override de lunité systemd
# ----------------------------------------------------------------
- name: "[grafana_alloy] Déploiement du service systemd (override)"
ansible.builtin.template:
src: alloy.service.j2
dest: /etc/systemd/system/alloy.service
owner: root
group: root
mode: "0644"
notify:
- Reload systemd
- Restart alloy
tags:
- grafana_alloy
- config
# ----------------------------------------------------------------
# Activation et démarrage du service
# ----------------------------------------------------------------
- name: "[grafana_alloy] Démarrage et activation du service alloy"
ansible.builtin.service:
name: alloy
state: started
enabled: true
tags:
- grafana_alloy
- service

View File

@@ -0,0 +1,27 @@
[Unit]
Description=Grafana Alloy
Documentation=https://grafana.com/docs/alloy/latest/
Wants=network-online.target
After=network-online.target
[Service]
User=alloy
Group=alloy
Type=simple
# Commande de démarrage finale et correcte, basée sur la sortie de "alloy run --help"
ExecStart=/usr/bin/alloy run /etc/alloy/config.alloy \
--storage.path=/var/lib/alloy \
--server.http.listen-addr=127.0.0.1:12345
# Sécurité via systemd
ReadWritePaths=/var/lib/alloy
ReadOnlyPaths=/etc/alloy
# Politiques de redémarrage et de limites de fichiers
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,50 @@
// =============================================================================
// Template Grafana Alloy pour Ansible
// Monitoring complet : Métriques Système + Statut Dnsmasq + Logs Système
// =============================================================================
logging {
level = "{{ alloy_log_level | default("info") }}"
format = "{{ alloy_log_format | default("logfmt") }}"
}
// --- Destinations ---
prometheus.remote_write "to_prometheus" {
endpoint {
url = "{{ alloy_prometheus_url | default("http://vision.lab.home.arnodo.fr:9090/api/v1/write") }}"
}
}
loki.write "to_loki" {
endpoint {
url = "{{ alloy_loki_url | default("http://vision.lab.home.arnodo.fr:3100/loki/api/v1/push") }}"
}
external_labels = {
source = "raspberrypi",
}
}
// --- Pipeline des métriques ---
prometheus.exporter.unix "system" {}
prometheus.exporter.dnsmasq "dnsmasq_status" {}
prometheus.scrape "local_metrics" {
targets = concat(
prometheus.exporter.unix.system.targets,
prometheus.exporter.dnsmasq.dnsmasq_status.targets,
)
forward_to = [prometheus.remote_write.to_prometheus.receiver]
}
// --- Pipeline des logs ---
loki.source.journal "system_logs" {
forward_to = [loki.relabel.add_job_label.receiver]
}
loki.relabel "add_job_label" {
rule {
target_label = "job"
replacement = "journal"
}
forward_to = [loki.write.to_loki.receiver]
}