Set up Grafana Loki for log aggregation and querying
✓Works with OpenClaudeYou are a DevOps engineer setting up centralized log aggregation. The user wants to deploy Grafana Loki, configure log sources, and query logs via LogQL.
What to check first
- Verify Docker and Docker Compose are installed:
docker --version && docker-compose --version - Check available disk space for log storage:
df -h /var/lib/docker(minimum 10GB recommended) - Ensure ports 3000 (Grafana) and 3100 (Loki) are not in use:
netstat -tuln | grep -E ':(3000|3100)'
Steps
- Create a
docker-compose.ymlwith Loki, Promtail (agent), and Grafana services - Configure Loki's
loki-config.yamlwith storage backend (filesystem or S3), retention policy, and schema config - Set up Promtail's
promtail-config.yamlto scrape logs from/var/logand other sources using job configs - Start services with
docker-compose up -dand verify health:curl http://localhost:3100/ready - Add Loki as a data source in Grafana (http://localhost:3000) with URL
http://loki:3100 - Create a dashboard or use Explore tab to run LogQL queries like
{job="varlogs"}or{job="docker"} | json | level="error" - Test label discovery with
/loki/api/v1/labelsendpoint to confirm Promtail is shipping logs - Configure retention and storage limits in loki-config.yaml
limits_configsection to prevent disk overflow
Code
# docker-compose.yml
version: '3.8'
services:
loki:
image: grafana/loki:latest
ports:
- "3100:3100"
volumes:
- ./loki-config.yaml:/etc/loki/local-config.yaml
- loki-storage:/loki
command: -config.file=/etc/loki/local-config.yaml
networks:
- loki-network
promtail:
image: grafana/promtail:latest
volumes:
- ./promtail-config.yaml:/etc/promtail/config.yaml
- /var/log:/var/log:ro
- /var/lib/docker/containers:/var/lib/docker/containers:ro
- /var/run/docker.sock:/var/run/docker.sock
command: -config.file=/etc/promtail/config.yaml
depends_on:
- loki
networks:
- loki-network
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Monitoring & Logging Skills
Other Claude Code skills in the same category — free to download.
Structured Logging
Implement structured logging (Winston, Pino)
Error Tracking
Set up error tracking (Sentry)
APM Setup
Set up Application Performance Monitoring
Log Rotation
Configure log rotation and management
Health Dashboard
Create health monitoring dashboard
Alert Rules
Configure alerting rules and notifications
Distributed Tracing
Set up distributed tracing
Metrics Collector
Implement custom metrics collection
Want a Monitoring & Logging skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.