RousselTMLEARNING

TP · Alloy: From Discovery to Expertise

Lab: Collecting and Shipping Logs to Loki

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

Logs searchable by level and environment.

Log pipeline #

Guided steps, with their solution.

  1. 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. 2. Read the files

    Why? local.file_match finds files, loki.source.file reads them and remembers its position.

    In config.alloy, read /var/log/myapp/*.log with the job=myapp label.
  3. 3. Process the lines

    Why? stage.labels takes an extracted value; a fixed value needs stage.static_labels.

    Extract level from the JSON to make it a label, add env=production and keep msg as text.
  4. 4. Send to Loki

    Why? In the Compose network, Loki is reached by its service name.

    Add the sending component.
  5. 5. Check

    Why? A healthy component does not prove that data arrives.

    Create a log file, start the stack and query Loki: you should see the env and level labels, and the texts paiement refusé and commande créée.

Difficulty level : ●●○○○ (2/5)

My progress

  • ⏱ Estimated time : ≈ 30 min

Sign in to track your progress and take notes. Sign in

💬 Ask a question

Course Glossary

Grafana Alloy

An open-source, vendor-neutral telemetry collector designed to replace Grafana Agent, fully compatible with OpenTelemetry (OTel).

Recommended Articles

Bonnes pratiques de collecte de logs avec Fluent Bit et Vector

Check-list de production pour la collecte de logs : structure, filtrage à la source, masquage, ta...

Grafana Alloy : Collecter les métriques système et les logs locaux

Découvrez comment configurer Grafana Alloy pour superviser le serveur sur lequel il s'exécute, av...

Grafana Alloy vs Grafana Agent vs Promtail : Lequel choisir ?

Découvrez l'évolution des collecteurs de télémétrie de l'écosystème Grafana. Comparatif détaillé ...

Grafana Loki vs Elasticsearch : La bataille du stockage de logs

Comparatif entre Loki, le système de logs inspiré par Prometheus, et Elasticsearch, le moteur de ...

LogQL (1/2) : requêter les logs (sélecteurs, filtres et parsers)

Apprendre LogQL : sélecteurs de flux, filtres de ligne, parsers json/logfmt/pattern/regexp, filtr...

Bonnes pratiques Grafana Loki : labels, requêtes, stockage et coûts

Bonnes pratiques Loki : choix des labels et cardinalité, structured metadata, requêtes LogQL perf...

LogQL (2/2) : transformer les logs en métriques

Créer des métriques à partir des logs avec LogQL : rate, count_over_time, bytes_rate, agrégations...

Traefik : les logs (journaux applicatifs et access logs)

Configurer les deux journaux de Traefik : le journal de fonctionnement (niveaux, format) et les a...

Fluent Bit : les outputs (sorties), routage et fiabilité de l'envoi

Envoyer les données de Fluent Bit : routage par Match et Match_Regex, sorties Loki, Elasticsearch...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!