cAdvisor (short for Container Advisor) is an open-source tool created by Google to collect, aggregate, process, and export resource usage and performance metrics for running containers.
It acts as a daemon that monitors resource isolation parameters, historical resource usage, and network statistics directly from the host node.
How It Works
cAdvisor doesn't require instrumenting code inside containers. Instead, it inspects the node environment where containers run:
- Queries Linux Kernel Structures: It pulls raw performance data directly from kernel mechanisms—primarily cgroups (control groups) for CPU, memory, and disk utilization, and network interfaces for throughput metrics.
- Discovers Running Containers: It automatically detects running containers across multiple runtimes (Docker, containerd, CRI-O, systemd containers).
- Exposes Metrics: It formats gathered data and exposes it over a /metrics HTTP endpoint (primarily in Prometheus format) for scrapers to ingest.
Role in Kubernetes
In Kubernetes, cAdvisor is not deployed as a standalone pod. Instead, it is built directly into the kubelet binary that runs on every node.
- The kubelet uses cAdvisor internally to monitor local container resource usage.
- It exposes cAdvisor metrics under the /metrics/cadvisor endpoint on the kubelet API port (typically 10250).
- Tools like Prometheus scrape this endpoint to collect system-wide container metrics (container_cpu_usage_seconds_total, container_memory_rss, container_network_transmit_bytes_total, etc.).
Core Capabilities
- Resource Usage Monitoring: Tracks real-time CPU utilization, memory breakdown (RSS, cache, swap), network I/O, and disk space usage per container.
- Historical Trend Aggregation: Keeps a small buffer of historical telemetry in memory for local inspection.
- Multi-Runtime Support: Works out of the box with containerd, Docker, and CRI-compliant container engines.
- Built-in Web UI: When run as a standalone binary or Docker container outside Kubernetes, it provides a lightweight built-in dashboard for quick visual inspection of container stats.
Summary of Metric Flow
Linux Kernel / cgroups --> cAdvisor --> Prometheus --> Grafana
cAdvisor sits right at the boundary between the underlying host/kernel layer and the monitoring stack, turning low-level kernel counters into structured metrics for alerting and visualization.


No comments:
Post a Comment