Skip to main content
We previously configured Prometheus to collect metrics from Linux hosts. This guide extends that setup to containerized environments. You can collect two complementary metric sets:
  • Docker Engine metrics — metrics about the Docker daemon/engine itself.
  • Per-container metrics — detailed container-level CPU, memory, filesystem, and process information exposed by cAdvisor.
Collecting both provides full-stack observability: engine-level health and per-container resource usage.
The image is an illustration of container metrics, showing how metrics can be scraped from containerized environments using Docker Engine and cAdvisor. It includes visual elements of servers, containers, and a monitoring icon.

1. Enable Docker Engine metrics

Docker can expose runtime metrics directly from the daemon. This is useful for monitoring the Docker engine itself (daemon CPU, errors, image/operation counts, etc.), and is configured on the host running Docker. Create or edit /etc/docker/daemon.json and add the metrics address and enable experimental features:
Exposing Docker metrics via the daemon is an experimental feature. Use it for testing or in environments where experimental features are acceptable.
Restart Docker and verify the metrics endpoint is reachable:
Then add a Prometheus scrape job to pull those metrics. If Prometheus runs on a different host, replace 127.0.0.1 with the Docker host IP or hostname:
Notes:
  • Use a stable hostname or IP for the target so Prometheus can reliably scrape metrics.
  • Consider network/firewall rules and authentication if scraping remotely.

2. Enable cAdvisor for per-container metrics

cAdvisor (Container Advisor) provides per-container metrics: CPU, memory, filesystem usage, process counts, and container uptime. Run cAdvisor on the Docker host so it can inspect containers and the host filesystem. Example docker-compose.yml for cAdvisor:
Start cAdvisor and confirm its metrics endpoint:
If you need the project source or more configuration options, see the cAdvisor repository: https://github.com/google/cadvisor.
cAdvisor requires elevated privileges and host volumes to provide accurate metrics. Run it only on trusted hosts and review security implications (privileged: true, host mounts).
Add a Prometheus scrape job for cAdvisor (replace the host/IP as needed):

3. What metrics to expect

  • Docker Engine metrics: engine/daemon-level metrics such as daemon CPU usage, queue lengths, API request durations, image build counts, and engine errors.
  • cAdvisor metrics: per-container resource metrics — CPU and memory usage by container, filesystem I/O, process counts inside containers, and container lifetime statistics.
Use Docker Engine metrics to monitor the health and behavior of the Docker daemon. Use cAdvisor for container-level resource visibility and troubleshooting.

4. Quick comparison

5. Troubleshooting checklist

  • If curl to the metrics endpoint times out, check firewall rules and whether Docker/cAdvisor is bound to localhost vs 0.0.0.0.
  • Use correct host/IP in Prometheus targets when Prometheus is remote.
  • Confirm container mounts and privileges for cAdvisor if metrics are missing or incomplete.
  • Check Docker daemon logs (sudo journalctl -u docker) for errors after editing daemon.json.
The image compares Docker Engine metrics with cAdvisor metrics, highlighting the differences in CPU/memory usage, process information, and container-specific metrics.

Watch Video

Practice Lab