docker.recipes

cAdvisor

beginner

Container resource usage and performance analyzer.

Overview

cAdvisor (Container Advisor) is Google's open-source container resource usage and performance monitoring tool that automatically discovers and monitors all containers running on a Docker host. Originally developed by Google for Kubernetes cluster monitoring, cAdvisor provides real-time resource usage statistics including CPU, memory, network, and filesystem metrics for every running container. The tool runs as a daemon that collects, aggregates, processes, and exports information about running containers, making it an essential component for container observability. cAdvisor operates by mounting the host system's key directories as read-only volumes, allowing it to access container runtime information directly from the Docker daemon and system cgroups. This privileged access enables comprehensive monitoring without requiring modifications to existing containers or applications. The tool automatically detects new containers and begins monitoring them immediately, providing historical usage data and real-time metrics through both a web interface and Prometheus-compatible endpoints. This monitoring solution is ideal for DevOps teams managing containerized applications, system administrators monitoring Docker hosts, and organizations implementing observability strategies. cAdvisor excels in environments where understanding container resource consumption is critical for capacity planning, performance optimization, and cost management. Its lightweight footprint and Google's active maintenance make it the de facto standard for Docker container monitoring across development, testing, and production environments.

Key Features

  • Real-time container resource monitoring with CPU, memory, network, and filesystem metrics collection
  • Automatic container discovery and monitoring without requiring application instrumentation
  • Web-based dashboard displaying historical usage graphs and current resource consumption
  • Prometheus metrics endpoint at /metrics for integration with monitoring and alerting systems
  • Container hierarchy visualization showing resource usage across container groups and images
  • Machine-level resource monitoring including total system capacity and utilization
  • RESTful API for programmatic access to container metrics and historical data
  • Support for multiple container runtimes including Docker, containerd, and CRI-O

Common Use Cases

  • 1Docker host monitoring for tracking resource utilization across all running containers
  • 2Prometheus and Grafana integration for comprehensive container observability dashboards
  • 3Container resource optimization by identifying memory leaks and CPU usage patterns
  • 4Capacity planning for Docker hosts by analyzing historical container resource trends
  • 5Development environment monitoring to understand application resource requirements
  • 6Multi-tenant container platform monitoring for resource allocation and billing purposes
  • 7CI/CD pipeline optimization by monitoring build container resource consumption

Prerequisites

  • Docker host with at least 512MB available RAM for cAdvisor container operation
  • Privileged container execution capability for accessing host system information
  • Port 8080 available on the host system for web interface and metrics access
  • Docker daemon running with API access for container discovery and monitoring
  • Host filesystem access permissions for mounting system directories as read-only volumes
  • Basic understanding of container metrics and resource monitoring concepts

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 cadvisor:
3 image: gcr.io/cadvisor/cadvisor:latest
4 container_name: cadvisor
5 restart: unless-stopped
6 privileged: true
7 volumes:
8 - /:/rootfs:ro
9 - /var/run:/var/run:ro
10 - /sys:/sys:ro
11 - /var/lib/docker/:/var/lib/docker:ro
12 - /dev/disk/:/dev/disk:ro
13 ports:
14 - "8080:8080"
15 networks:
16 - cadvisor-network
17
18networks:
19 cadvisor-network:
20 driver: bridge

.env Template

.env
1# cAdvisor default configuration

Usage Notes

  1. 1Docs: https://github.com/google/cadvisor
  2. 2Web UI at http://localhost:8080 - view container stats
  3. 3Prometheus metrics at http://localhost:8080/metrics
  4. 4Shows CPU, memory, network, filesystem per container
  5. 5Add to Prometheus: - job_name: cadvisor, static_configs: targets: ['cadvisor:8080']
  6. 6Google-maintained - standard for Docker container monitoring

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 cadvisor:
5 image: gcr.io/cadvisor/cadvisor:latest
6 container_name: cadvisor
7 restart: unless-stopped
8 privileged: true
9 volumes:
10 - /:/rootfs:ro
11 - /var/run:/var/run:ro
12 - /sys:/sys:ro
13 - /var/lib/docker/:/var/lib/docker:ro
14 - /dev/disk/:/dev/disk:ro
15 ports:
16 - "8080:8080"
17 networks:
18 - cadvisor-network
19
20networks:
21 cadvisor-network:
22 driver: bridge
23EOF
24
25# 2. Create the .env file
26cat > .env << 'EOF'
27# cAdvisor default configuration
28EOF
29
30# 3. Start the services
31docker compose up -d
32
33# 4. View logs
34docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/cadvisor/run | bash

Troubleshooting

  • cAdvisor shows 'unable to find Docker' error: Verify Docker daemon is running and /var/run/docker.sock is accessible
  • Blank or missing container metrics: Ensure privileged mode is enabled and system directories are properly mounted
  • High memory usage by cAdvisor container: Reduce metrics retention period or upgrade host memory for large container environments
  • Permission denied accessing /sys filesystem: Verify container runs with privileged flag and host directories are mounted correctly
  • Missing network statistics: Check that /proc and /sys/class/net are accessible and not restricted by security policies
  • Prometheus metrics endpoint returns empty data: Confirm cAdvisor is discovering containers and verify /metrics endpoint accessibility

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space