Grafana Loki is a lighter-weight alternative to the ELK Stack, designed to index only log metadata (not full-text content), resulting in significantly lower resource requirements — a practical choice for smaller VPS deployments.
Why Loki Uses Fewer Resources Than ELK
Unlike Elasticsearch, which fully indexes log content for powerful full-text search, Loki indexes only labels (metadata like source, level, service name), storing the actual log content more cheaply — a deliberate trade-off reducing resource requirements substantially, particularly relevant for smaller-scale VPS deployments.
Prerequisites
- Ubuntu 22.04/24.04 VPS: 2 vCPU, 2-4 GB RAM (much lighter than ELK)
- Docker installed
- Grafana already installed (see How to Set Up Prometheus and Grafana for VPS Monitoring) for visualization
Step 1 — Run Loki
docker run -d \
--name loki \
--restart unless-stopped \
-p 3100:3100 \
-v loki-data:/loki \
grafana/loki:latest
Step 2 — Verify Loki Is Running
curl http://localhost:3100/ready
Step 3 — Install Promtail (Loki's Log Shipper)
docker run -d \
--name promtail \
--restart unless-stopped \
-v /var/log:/var/log:ro \
-v $(pwd)/promtail-config.yml:/etc/promtail/config.yml \
grafana/promtail:latest \
-config.file=/etc/promtail/config.yml
Step 4 — Configure Promtail
nano promtail-config.yml
server:
http_listen_port: 9080
positions:
filename: /tmp/positions.yaml
clients:
- url: http://YOUR_LOKI_SERVER_IP:3100/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*.log
Step 5 — Add Loki as a Data Source in Grafana
In Grafana: Connections → Data Sources → Add Data Source → Loki, enter your Loki server's URL.
Step 6 — Explore Logs in Grafana
Under Explore, select the Loki data source and use LogQL (Loki's query language, similar in spirit to Prometheus's PromQL) to search and filter logs.
Basic LogQL Query Examples
{job="varlogs"} |= "error"
{job="varlogs"} | json | level="error"
Building Log-Based Dashboards
Since Loki integrates directly with Grafana, you can combine log-derived panels alongside your existing Prometheus metrics dashboards in one unified view — a significant convenience if already using Grafana for metrics.
Setting Log Retention
limits_config:
retention_period: 720h
Configure retention based on your storage capacity and actual need to look back at historical logs — shorter retention reduces storage costs.
When to Choose Loki Over ELK
| Factor | Loki | ELK Stack |
|---|---|---|
| Resource requirements | Much lower | Higher |
| Full-text search power | More limited | More powerful |
| Best for | Smaller deployments, teams already using Grafana | Complex search needs, larger-scale log analysis |
Common Errors
Promtail runs but no logs appear in Grafana — verify the Loki URL in Promtail's config is correct and reachable, and check Promtail's own logs for connection errors.
Continue Reading
- How to Set Up Prometheus and Grafana for VPS Monitoring
- How to Set Up Centralized Logging with the ELK Stack (Elasticsearch, Logstash, Kibana)
- Structured Logging Best Practices for Easier Debugging
Browse more articles in Advanced Observability & Incident Management.