- Collect
- Label
- Store
- Query
1) Collect — lightweight agents near your apps
Loki does not read application processes directly. Instead, a lightweight agent runs close to your applications, tails log files or listens to stdout/stderr, and pushes log entries to Loki’s HTTP API. Most common agents:- Grafana Alloy Agent (recommended)
- Fluentd
- Fluent Bit
- Logstash
- OpenTelemetry Collector
Use a lightweight forwarder (e.g.,
Grafana Alloy Agent or Fluent Bit) on each node to minimize resource usage and simplify log shipping. Agents add labels as the logs are forwarded so streams are grouped at ingest time.2) Label — group streams and keep indexing minimal
When logs arrive, Loki groups them into streams using the labels attached by the agent (for example,job or env). Loki indexes only those labels; the log lines themselves are stored exactly as they were produced. This selective indexing is the core of Loki’s cost and performance benefits.
Example mapping of log lines into labeled streams:
Because Loki only indexes labels, choose them carefully. If you need to search arbitrary text across logs frequently, consider adding labels for those fields or using LogQL parsing operators — otherwise full-text search will be slower or unavailable.
3) Store — compact index + compressed chunks in object storage
Loki stores two things side-by-side:- A compact index of labels and time ranges that points to log chunks.
- The compressed log chunks that contain the raw log lines.
- Small, fast index lookups (label queries are quick).
- Low-cost, scalable storage of the large log payloads.
- Retention and lifecycle policies handled by the object store.
4) Query — LogQL, logcli, and Grafana
Loki exposes a query language called LogQL for filtering, parsing, and aggregating logs. Queries can be executed:- From the CLI using
logcli - From Grafana, where logs appear side-by-side with metrics and dashboards
Concrete setup example
Imagine three machines:- Machine 1: Runs the Loki server and object-store connector.
- Machine 2: Runs your application A + a local agent that tails logs and forwards them with labels.
- Machine 3: Runs your application B + a local agent.

- Grafana Loki — https://grafana.com/oss/loki/
- LogQL documentation — https://grafana.com/docs/loki/latest/logql/
- logcli — https://grafana.com/docs/loki/latest/tools/logcli/
- Grafana Alloy Agent — https://grafana.com/docs/agents/latest/
- Fluentd — https://www.fluentd.org/
- Fluent Bit — https://fluentbit.io/
- OpenTelemetry Collector — https://opentelemetry.io/docs/collector/
- Amazon S3 — https://aws.amazon.com/s3/
- Google Cloud Storage — https://cloud.google.com/storage
- Azure Blob Storage — https://azure.microsoft.com/en-us/services/storage/blobs/