On Debian 13:
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable --now docker
On RHEL 10:
sudo dnf install -y docker
sudo systemctl enable --now docker
Basic installation:
docker run -d \
--name=cadvisor \
--restart=unless-stopped \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
--privileged \
--device=/dev/kmsg \
google/cadvisor:latest
For systems with cgroups v2:
docker run -d \
--name=cadvisor \
--restart=unless-stopped \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--volume=/sys/fs/cgroup:/sys/fs/cgroup:ro \
--publish=8080:8080 \
--detach=true \
--privileged \
google/cadvisor:latest
Download the binary:
cd /tmp
CADVISOR_VERSION=v0.49.1
wget https://github.com/google/cadvisor/releases/download/${CADVISOR_VERSION}/cadvisor-${CADVISOR_VERSION}-linux-amd64
sudo mv cadvisor-${CADVISOR_VERSION}-linux-amd64 /usr/local/bin/cadvisor
sudo chmod +x /usr/local/bin/cadvisor
Create systemd service:
sudo tee /etc/systemd/system/cadvisor.service >/dev/null <<'EOF'
[Unit]
Description=cAdvisor
Documentation=https://github.com/google/cadvisor
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/cadvisor -logtostderr -port 8080
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable --now cadvisor
Create configuration directory:
sudo mkdir -p /etc/cadvisor
Create configuration file:
sudo tee /etc/cadvisor/cadvisor.conf >/dev/null <<'EOF'
{
"port": 8080,
"housekeeping_interval": "10s",
"max_housekeeping_interval": "60s",
"allow_dynamic_housekeeping": true,
"storage_duration": "2m0s"
}
EOF
Run with config:
cadvisor -logtostderr -port 8080 -config /etc/cadvisor/cadvisor.conf
On UFW:
sudo ufw allow 8080/tcp
On firewalld:
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
Open http://SERVER_IP:8080 to access the cAdvisor web interface.
Test the API:
curl http://localhost:8080/api/v2.0/stats?num_stats=1
View containers:
curl http://localhost:8080/api/v2.0/containers/
cAdvisor exposes Prometheus metrics by default. To scrape with Prometheus:
Add to prometheus.yml:
scrape_configs:
- job_name: 'cadvisor'
static_configs:
- targets: ['localhost:8080']
Metrics endpoint: http://SERVER_IP:8080/metrics
Import cAdvisor dashboard to Grafana:
193 (Docker and System Monitoring)# All containers
curl http://localhost:8080/api/v2.0/containers/
# Specific container
curl http://localhost:8080/api/v2.0/containers/<container_id>?num_stats=5
curl http://localhost:8080/healthz
curl http://localhost:8080/api/v2.0/machine
See cAdvisor Hardening.
Need professional assistance with your monitoring infrastructure? Our team provides:
Get in touch: office@linux-server-admin.com | Contact Page
Prefer automation? See cAdvisor Ansible Setup for an example playbook.
Prefer containers? See cAdvisor Docker Setup.
See cAdvisor Configuration for configuration guidance.
See cAdvisor Security for hardening guidance.