Monitoring Docker Logs and Metrics with Grafana, Loki, Promtail, Prometheus, and cAdvisor

Recently, I configured Docker log collection and container monitoring using Grafana. This setup provides both logs and performance metrics in dashboard, making Docker monitoring much easier.

Architecture

Docker Logs

Docker Containers → Promtail → Loki → Grafana

Docker Metrics

Docker Containers → cAdvisor → Prometheus → Grafana

Collecting Docker Logs with Promtail

Promtail automatically discovers Docker containers and sends logs to Loki. Container information such as container name, container ID, image name, and host name can be added as labels. This makes log filtering very easy inside Grafana.

Benefits
• Centralized Docker logs
• Search logs by container name
• Filter logs by host
• Easy troubleshooting
• Real-time log monitoring

Grafana Dashboard for Docker Logs
I created a Grafana dashboard to visualize Docker container logs.
Key features:
• Total log count
• Error log count
• Warning log count
• Live log viewer
• Host filter
• Container filter

A custom Container variable was added so users can quickly select a specific container and view only its logs.

Configure Promtail for Docker Logs

server:
http_listen_port: 9080

positions:
filename: /tmp/positions.yaml

clients:
- url: http://LOKI_SERVER:3100/loki/api/v1/push

scrape_configs:
- job_name: docker

docker_sd_configs:
- host: unix:///var/run/docker.sock
refresh_interval: 5s

relabel_configs:

- source_labels: \['\__meta_docker_container_name'\]
regex: '/(.\*)'
target_label: 'container'
replacement: '$1'

- source_labels: \['\__meta_docker_container_id'\]
target_label: 'container_id'

- source_labels: \['\__meta_docker_container_image'\]
target_label: 'image'

- target_label: 'job'
replacement: 'docker'

- target_label: 'host'
replacement: 'SERVER_NAME'

pipeline_stages:
- docker: {}

Verify Promtail

systemctl status promtail

Check logs:

journalctl -u promtail –f

Monitoring Docker Metrics with cAdvisor

For container performance monitoring, I deployed cAdvisor. It collects Docker container metrics and exposes them to Prometheus.

Metrics collected include:

  • Total container count
  • Container status
  • CPU usage per container
  • Memory usage per container
  • Network traffic per container

Grafana Dashboard for Docker Metrics

The metrics dashboard provides a quick overview of container health and performance.

Dashboard panels include:

  • Running containers
  • Container uptime
  • CPU utilization
  • Memory consumption
  • Network traffic
  • Container status overview

This helps identify resource-heavy containers and monitor overall Docker environment health.

Install cAdvisor

cAdvisor collects Docker container metrics such as CPU, Memory, Network, and Container Status.

docker run -d \\
--name cadvisor \\
-p 8081:8080 \\
-v /:/rootfs:ro \\
-v /var/run/docker.sock:/var/run/docker.sock:ro \\
-v /sys:/sys:ro \\
-v /var/lib/docker:/var/lib/docker:ro \\
--restart unless-stopped \\
--privileged \\
gcr.io/cadvisor/cadvisor:v0.49.1

Verify:

docker ps

Open:

http://SERVER_IP:8081

Configure Prometheus
Add cAdvisor target.

scrape_configs:

  - job_name: cadvisor

    static_configs:

      - targets:

          - SERVER_IP:8081

Reload Prometheus:

systemctl restart prometheus

Verify target:

http://PROMETHEUS_IP:9090/targets

Target should show UP.

Add Prometheus Data Source in Grafana
Navigate:

Grafana → Connections → Data Sources

Add:

Prometheus

URL:

http://PROMETHEUS_IP:9090

Build Docker Monitoring Dashboard

Conclusion
Using Promtail, Loki, Grafana, Prometheus, and cAdvisor together creates a complete Docker monitoring solution. Logs and metrics are available in one place, making troubleshooting faster and improving visibility into Docker environments.

For the record:

Warning

Promtail is end of life (EOL) as of March 2, 2026. Commercial support has ended. No future support or updates will be provided. All future feature development will occur in Grafana Alloy.

Replacing Promtail with Alloy will better future-proof the architecture.

Thanks @jangaraj for your suggestion.i will try with alloy.