How to Monitor Docker Containers with cAdvisor and Prometheus
cAdvisor (Container Advisor) collects resource usage metrics from running containers. Paired with Prometheus, it gives you comprehensive monitoring for Docker workloads on your Breeze server.
Setting Up the Monitoring Stack
Create a docker-compose.yml for the monitoring stack:
services:
cadvisor:
image: gcr.io/cadvisor/cadvisor:latest
ports:
- "8081:8080"
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
restart: unless-stopped
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
restart: unless-stopped
volumes:
prometheus_data:
Configuring Prometheus
Create prometheus.yml to scrape cAdvisor metrics:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'cadvisor'
static_configs:
- targets: ['cadvisor:8080']
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
Launching the Stack
docker compose up -d
# Access cAdvisor at http://your-breeze-ip:8081
# Access Prometheus at http://your-breeze-ip:9090
Useful Prometheus Queries
container_memory_usage_bytes— memory usage per containerrate(container_cpu_usage_seconds_total[5m])— CPU usage ratecontainer_network_receive_bytes_total— network ingresscontainer_fs_usage_bytes— filesystem usage
Setting Up Alerts
Add alert rules to Prometheus for proactive monitoring:
groups:
- name: container_alerts
rules:
- alert: HighMemoryUsage
expr: container_memory_usage_bytes > 1e+09
for: 5m
labels:
severity: warning
annotations:
summary: "Container {{ $labels.name }} using over 1GB RAM"