What you will learn in this TP
- Read log files
- Extract and add labels
- Send to Loki and check
Introduction #
What you will learn in this section
- Read log files
- Extract and add labels
- Send to Loki and check
Context. An application writes JSON logs to files, and nobody reads them before an incident. You centralize them in Loki.
Prerequisites: Docker Compose, curl · Estimated time: 30 min
Log pipeline #
Guided steps, with their solution.
1. Prepare the stack
Why? The volume keeps read positions: without it, Alloy would re-read everything at each restart.
Write a Compose file with Loki and Alloy.2. Read the files
Why?
Inlocal.file_matchfinds files,loki.source.filereads them and remembers its position.config.alloy, read/var/log/myapp/*.logwith thejob=myapplabel.3. Process the lines
Why?
Extractstage.labelstakes an extracted value; a fixed value needsstage.static_labels.levelfrom the JSON to make it a label, addenv=productionand keepmsgas text.4. Send to Loki
Why? In the Compose network, Loki is reached by its service name.
Add the sending component.5. Check
Why? A
Create a log file, start the stack and query Loki: you should see thehealthycomponent does not prove that data arrives.envandlevellabels, and the textspaiement refuséandcommande créée.
Difficulty level : ●●○○○ (2/5)
My progress
Sign in to track your progress and take notes. Sign in
Course Glossary
Grafana Alloy
An open-source, vendor-neutral telemetry collector designed to replace Grafana Agent, fully compatible with OpenTelemetry (OTel).
Recommended Articles
Grafana Alloy: Log Management with Loki
Discover how to configure Grafana Alloy to read log files, journald, or network streams, process ...
Collecter des logs vers Loki : Alloy, Promtail, Docker et OpenTelemetry
Envoyer des logs vers Loki : Grafana Alloy, Promtail, driver Docker, OTLP, bons labels, parsing e...
La stack LGTM (Loki, Grafana, Tempo, Mimir) : architecture et mise en place
Comprendre la stack LGTM de Grafana Labs : Loki pour les logs, Grafana pour la visualisation, Tem...
Grafana Loki : le système de logs inspiré de Prometheus
Découvrir Grafana Loki : philosophie d'indexation par labels, architecture (distributor, ingester...
Référence des Composants Grafana Alloy
Un guide de référence complet sur tous les composants disponibles dans Grafana Alloy, organisé pa...
Grafana Alloy: The importance of Self-Monitoring
Discover why and how to configure Grafana Alloy so that it monitors itself, collecting its own lo...
Grafana Alloy : Collecte et Transformation de Télémétrie
Apprenez à utiliser Grafana Alloy pour collecter, transformer et acheminer logs, métriques et tra...
Alerter sur les logs avec le Ruler de Loki
Mettre en place des alertes et des recording rules LogQL avec le Ruler Loki : configuration, fich...
Corréler traces, logs, métriques et profils dans Grafana
Relier Tempo aux logs (Loki), aux métriques (Prometheus) et aux profils (Pyroscope) : tracesToLog...