RousselTMLEARNING

Article · Alloy: From Discovery to Expertise

Log Sources

1. Log sources #

Reading files, journald, and network receivers.

Where do logs come from? #

Available in: ✓ OSS ✓ Enterprise ✓ Cloud

The logs chain in Alloy
ComponentSource
loki.source.fileFiles, with rotation handling
loki.source.journalsystemd journal
loki.source.dockerDocker containers
loki.source.kubernetesPods, through the Kubernetes API
loki.source.syslogSyslog messages received over the network
loki.source.apiHTTP reception, in Loki format
otelcol.receiver.otlpOpenTelemetry logs from applications

Reading files #

local.file_match finds files, loki.source.file reads them. Target labels, here job, travel with each line; __path__ designates the file and becomes the filename label.

local.file_match "app" {
  path_targets = [{ "__path__" = "/var/log/app/*.log", "job" = "app" }]
}

loki.source.file "app" {
  targets    = local.file_match.app.targets
  forward_to = [loki.write.local.receiver]
}

loki.write "local" {
  endpoint {
    url = "http://loki:3100/loki/api/v1/push"
  }
}

Alloy remembers its position in --storage.path: at restart, it resumes where it stopped. If this folder is not kept, the whole file is re-read and Loki receives duplicates.

Nothing arrives? Check permissions first: the alloy user must be able to read the files. On Debian, add it to the adm group for /var/log.

The systemd journal #

loki.source.journal "systeme" {
  forward_to = [loki.write.local.receiver]
  labels     = { job = "journal" }
}

loki.write "local" {
  endpoint {
    url = "http://loki:3100/loki/api/v1/push"
  }
}

loki.source.journal can also transform internal journal fields with relabel_rules, for example to keep the unit name.

Checking without Loki #

To see what Alloy sees, plug loki.echo into forward_to: each line is written to Alloy's logs with its labels. The tests for this course relied on this component.

📄 Grafana Alloy: Log Management with Loki →

My progress

  • ⏱ Estimated time : ≈ 4 min

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

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Recent discussions about this course

Ask a question about this lesson →See all discussions about this course

Course Glossary

Grafana Alloy

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

Recommended Articles

Collecting logs into Loki: Alloy, Promtail, Docker and OpenTelemetry

Send logs to Loki: Grafana Alloy, Promtail, the Docker driver, OTLP, good labels, parsing and enr...

Grafana Alloy: collecting and transforming telemetry

Learn how to use Grafana Alloy to collect, transform and route logs, metrics and traces. Discover...

Grafana Alloy vs Grafana Agent vs Promtail: which one to choose?

Discover how telemetry collectors have evolved in the Grafana ecosystem. A detailed comparison of...

Grafana Alloy: collecting system metrics and local logs

Learn how to configure Grafana Alloy to monitor the server it runs on, with a focus on configurat...

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 components reference

A complete reference guide to all the components available in Grafana Alloy, organized by categor...

The LGTM stack (Loki, Grafana, Tempo, Mimir): architecture and setup

Grafana Labs' LGTM stack: Loki for logs, Grafana for visualization, Tempo for traces, Mimir for m...

Cribl Edge: collecting close to the sources

Deploying Cribl Edge on Linux, Windows and Kubernetes: the agent's role, Fleets and Subfleets, co...

OpenTelemetry Collector, Grafana Alloy and Bindplane: comparing three approaches to telemetry pipelines

Detailed comparison of three ways to manage telemetry pipelines: the OpenTelemetry Collector in Y...

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!