cAdvisor (Container Advisor) is an open-source daemon from Google that collects, aggregates, and exposes resource usage and performance metrics for every running container on a host. Unlike Docker’s built-in docker stats, cAdvisor exposes its data in Prometheus format, making it a natural fit for scraping alongside Node Exporter. This tutorial covers running cAdvisor on RHEL 9, verifying its built-in web UI, wiring it to Prometheus, and importing a ready-made Grafana dashboard for instant container visibility.
Prerequisites
- RHEL 9 server with Docker installed and running (
systemctl status docker) - At least one container running so there is data to observe
- Prometheus installed and configured to accept new scrape jobs
- Grafana connected to Prometheus (for the dashboard import step)
Step 1 — Run cAdvisor as a Docker Container
cAdvisor is distributed as a container image and requires read-only access to several host paths to gather metrics from the kernel and Docker runtime.
docker run -d
--name cadvisor
--restart unless-stopped
-p 8080:8080
--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
--privileged
--device=/dev/kmsg
gcr.io/cadvisor/cadvisor:latest
docker ps --filter name=cadvisor # confirm it is "Up"
docker logs cadvisor --tail 20 # inspect startup
The --privileged flag and /dev/kmsg device are required on RHEL 9 for full cgroup v2 metric collection. The --restart unless-stopped policy means cAdvisor will restart automatically after a server reboot or Docker daemon restart.
Step 2 — Open the Firewall and Verify the cAdvisor Web UI
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports # confirm 8080/tcp appears
Navigate to http://<server-ip>:8080 in a browser. You will see a per-container resource dashboard showing real-time CPU, memory, network, and filesystem usage graphs. Click any container name to drill into its individual statistics. The raw Prometheus metrics endpoint is available at http://<server-ip>:8080/metrics.
Step 3 — Add cAdvisor as a Prometheus Scrape Target
Edit /etc/prometheus/prometheus.yml and add a new job under scrape_configs:
- job_name: 'cadvisor'
static_configs:
- targets: ['localhost:8080']
metric_relabel_configs:
# Drop high-cardinality per-CPU metrics to save storage
- source_labels: [__name__]
regex: 'container_cpu_usage_seconds_total'
action: keep
For a complete metric set (recommended unless storage is constrained), omit the metric_relabel_configs block entirely. Reload Prometheus to apply the change:
sudo systemctl reload prometheus
# Confirm the target appears as UP
curl -s http://localhost:9090/api/v1/targets | python3 -m json.tool | grep cadvisor
Step 4 — Key Container Metrics to Query
Once Prometheus is scraping cAdvisor, the following PromQL queries cover the most important container resource dimensions:
# CPU usage rate per container (cores consumed per second)
rate(container_cpu_usage_seconds_total{name!=""}[5m])
# Memory usage in bytes (resident set size)
container_memory_usage_bytes{name!=""}
# Memory working set (more accurate — excludes reclaimable cache)
container_memory_working_set_bytes{name!=""}
# Network bytes received per second
rate(container_network_receive_bytes_total{name!=""}[5m])
# Network bytes transmitted per second
rate(container_network_transmit_bytes_total{name!=""}[5m])
# Filesystem usage
container_fs_usage_bytes{name!=""}
# Container restart count
kube_pod_container_status_restarts_total # Kubernetes only
# For plain Docker:
container_start_time_seconds{name!=""}
The filter {name!=""} excludes system-level cgroup entries (the root cgroup and pod sandboxes) and returns only named Docker containers.
Step 5 — Import a Grafana Dashboard for Container Metrics
Grafana community dashboard ID 14282 (“Docker and Host Monitoring”) provides pre-built panels for container CPU, memory, network, and storage, with dropdowns to filter by host and container name.
# Import via the Grafana UI:
# 1. Click Dashboards → Import
# 2. Enter dashboard ID: 14282
# 3. Click Load
# 4. Select your Prometheus datasource from the dropdown
# 5. Click Import
# Alternatively, download and import via API:
curl -s https://grafana.com/api/dashboards/14282/revisions/latest/download
-o cadvisor-dashboard.json
curl -X POST http://admin:password@localhost:3000/api/dashboards/import
-H "Content-Type: application/json"
--data-binary "{"dashboard": $(cat cadvisor-dashboard.json), "overwrite": true, "folderId": 0}"
Step 6 — Set Resource Limits and Alert on Threshold Breach
Pair cAdvisor metrics with Prometheus alerting rules to receive notifications when a container exceeds its resource budget. Add the following to /etc/prometheus/rules/cadvisor.yml:
groups:
- name: cadvisor
rules:
- alert: ContainerHighMemory
expr: |
container_memory_working_set_bytes{name!=""} /
container_spec_memory_limit_bytes{name!="",container_spec_memory_limit_bytes>0}
> 0.9
for: 5m
labels:
severity: warning
annotations:
summary: "Container {{ $labels.name }} memory > 90% of limit"
- alert: ContainerCPUThrottling
expr: |
rate(container_cpu_throttled_seconds_total{name!=""}[5m]) > 0.25
for: 10m
labels:
severity: warning
annotations:
summary: "Container {{ $labels.name }} is CPU-throttled"
Reload Prometheus after saving the rules file: sudo systemctl reload prometheus. The alerts will fire to Alertmanager (and any configured receivers such as Slack or PagerDuty) when conditions are met.
Conclusion
cAdvisor is now running on RHEL 9 in a privileged Docker container, collecting CPU, memory, network, and filesystem metrics for every running container and exposing them at a Prometheus-compatible /metrics endpoint. Prometheus is scraping those metrics every 15 seconds, and Grafana dashboard ID 14282 gives you an instant visual overview of container health across the host. Alerting rules ensure your team is notified before memory limits are exhausted or CPU throttling begins to impact application performance.
Next steps: How to Build Grafana Dashboards for Linux Server Metrics on RHEL 9, How to Set Up Uptime Kuma for Service Monitoring on RHEL 9, and How to Use Prometheus Blackbox Exporter for Endpoint Monitoring on RHEL 9.