Export Docker container metrics (memory usage, limits, and reservations) to Prometheus.
- Collcts memory metrics per container.
- Supports Docker Swarm, Rancher, and Compose labels for stack/service identification.
- Compatible with cgroups v1 and v2.
- Exposes
/metricsendpoint for Prometheus scraping.
You can run the exporter as a Docker container. Example:
services:
prometheus-integration:
image: <your-docker-username>/prometheus-integration:latest
privileged: true
environment:
DOCKER_CLUSTER_CGROUP_VERSION: v2
network_mode: host
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /sys:/host:ro
pid: host
ports:
- "9476:9476"- The exporter reads container cgroups from
/host/sys. - If you use cgroups v2, use
DOCKER_CLUSTER_CGROUP_VERSION=v2. - The
/var/run/docker.sockvolume allows the exporter to request Docker container info.
- Build binary with Go 1.21:
go build -o prometheus-integration main.go- Run exporter:
./prometheus-integration- Metrics are available at
http://localhost:9476/metrics.
version: '3.9'
services:
prometheus-integration:
build: .
container_name: prometheus-docker-integration
privileged: true
pid: host
network_mode: host
environment:
DOCKER_CLUSTER_CGROUP_VERSION: v2
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /sys:/host:ro
ports:
- "9476:9476"
restart: unless-stopped| Metric | Description |
|---|---|
| docker_container_memory_usage_bytes | Memory usage of container in bytes (excluding cache) |
| docker_container_memory_reservation_bytes | Memory reserved for container |
| docker_container_memory_limit_bytes | Memory limit for container |
DOCKER_CLUSTER_CGROUP_VERSIONโ Optional,v1(default) orv2.