DEV Community

Alex Spinov
Alex Spinov

Posted on

Grafana Loki Has a Free API — Log Aggregation Without the Cost

Grafana Loki is a log aggregation system inspired by Prometheus. It indexes labels, not content — making it 10x cheaper than Elasticsearch for logs.

What Is Loki?

Loki stores logs efficiently by only indexing metadata (labels) while keeping log lines compressed in object storage. Query with LogQL.

Why Loki?

  • 10x cheaper than Elasticsearch
  • Native Grafana integration
  • Prometheus-like label model
  • S3/GCS/MinIO storage
  • Multi-tenant

Quick Start

docker run -p 3100:3100 grafana/loki:latest
Enter fullscreen mode Exit fullscreen mode

HTTP API

# Push logs
curl -X POST http://localhost:3100/loki/api/v1/push \
  -H "Content-Type: application/json" \
  -d '{"streams":[{"stream":{"app":"myapp","level":"error"},"values":[["1679500000000000000","Connection refused to database"]]}]}'

# Query logs
curl -G http://localhost:3100/loki/api/v1/query_range \
  --data-urlencode "query={app=\"myapp\"}" \
  --data-urlencode "limit=10"

# Query with filter
curl -G http://localhost:3100/loki/api/v1/query_range \
  --data-urlencode "query={app=\"myapp\"} |= \"error\""
Enter fullscreen mode Exit fullscreen mode

Use Cases

  1. Centralized logging — all app logs in one place
  2. Kubernetes logging — native k8s integration
  3. Cost reduction — replace expensive ELK stacks
  4. Alert on logs — Grafana alerting rules
  5. Compliance — long-term log retention on S3

Loki vs Alternatives

Feature Loki Elasticsearch Datadog
Index strategy Labels only Full-text Full-text
Storage cost Low High Very high
Query language LogQL KQL Custom
Grafana native Yes Plugin Plugin

Need web data at scale? Check out my scraping tools on Apify or email spinov001@gmail.com for custom solutions.

Top comments (0)