RousselTMLEARNING

Observability

Grafana Loki: the Prometheus-inspired log system

Discover Grafana Loki: the label-indexing philosophy, architecture (distributor, ingester, querier, compactor), comparison with Elasticsearch, deployment modes and use cases.

1. Why Loki? #

A different philosophy from Elasticsearch.

Index the labels, not the content #

Available in: ✓ OSS ✓ Enterprise ✓ Cloud Loki open source, Enterprise Logs and Grafana Cloud Logs

Loki is a log aggregation system created by Grafana Labs, inspired by Prometheus. Where Elasticsearch builds an inverted index of every word, Loki only indexes the labels of a log stream (app, namespace, env...). The content of the lines is simply compressed and stored, then filtered at read time. The result: a tiny index, cheap storage and simpler operations.

Loki indexing principle
Labels are used to select streams; the content is filtered on the fly.
CriterionLokiElasticsearch / ELK
IndexLabels onlyFull-text inverted index
Storage costLow (compressed chunks, object storage)High (large indexes, fast disks)
Full-text searchFiltering at read time (distributed grep)Very fast thanks to the index
Metrics integrationLogQL close to PromQL, metrics from logsElastic-specific aggregations
OperationsSimpler, largely statelessMore complex (shards, mappings)

2. The architecture #

Write path, read path.

The components #

Loki components
In microservices mode, each component can be scaled independently.
ComponentRole
DistributorReceives logs, validates them, distributes streams to ingesters (hash of the labels)
IngesterKeeps recent logs in memory + WAL, builds chunks, then sends them to storage
Query FrontendSplits and caches queries, fair queueing
QuerierRuns queries against the ingesters (recent) and storage (historical)
CompactorCompacts indexes, applies retention and deletions
RulerEvaluates LogQL alerting and recording rules
Index GatewayServes the index to queriers (optional)

3. Deployment modes #

From the laptop to massive production.

Three modes #

ModePrincipleWhen to use it
Monolithic (-target=all)A single binary, all componentsTesting, small volumes (< ~20 GB/day)
Simple scalable (read / write / backend)Three groups of components to scaleMedium production, up to a few TB/day
MicroservicesEach component is a separate deploymentVery large volumes, fine-grained control
# Un même binaire, plusieurs cibles
loki -config.file=loki.yaml -target=all          # monolithique
loki -config.file=loki.yaml -target=write        # simple scalable : chemin d'écriture
loki -config.file=loki.yaml -target=read         # lecture
loki -config.file=loki.yaml -target=backend      # compactor, ruler, index gateway
loki -config.file=loki.yaml -modules             # lister les modules

Use cases #

  • Application and container logs collected from Kubernetes with the same labels as Prometheus metrics.
  • Correlation: go from an alert or a metric to the corresponding logs in Grafana in one click.
  • Metrics from logs: count errors, compute latencies from access logs.
  • Audit and security: low-cost long-term retention.
Good practice: If you very often search for rare words in terabytes of logs without knowing the stream, a full-text engine will remain faster. Loki excels when you start from a context (service, pod, environment).

Related articles

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

Understand Grafana Labs' LGTM stack: Loki for logs, Grafana for visualization, Tempo for traces and Mimir for…

Installing Grafana Loki (Docker Compose, binary and Helm)

Install and validate Grafana Loki: minimal configuration, Docker Compose with Grafana and Alloy, binary insta…

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

Send logs to Loki: Grafana Alloy, Promtail, the Docker driver, OTLP, good labels, parsing and enrichment, Kub…

Keep learning

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!