What is cadvisor?
cAdvisor (short for Container Advisor) is an open‑source tool that runs on a host machine and automatically collects, aggregates, and displays resource usage and performance metrics for Docker containers (CPU, memory, network, filesystem, etc.). It provides a web UI and an API so you can see how each container is behaving in real time.
Let's break it down
- Agent: cAdvisor is a small daemon you install on each server that you want to monitor.
- Data collection: It reads information from the Linux kernel (cgroups, /proc, /sys) to know how much CPU, RAM, disk I/O, and network each container uses.
- Storage: By default it keeps recent data in memory, but you can configure it to send data to external time‑series databases like Prometheus.
- Visualization: It ships a built‑in web page (usually at http://localhost:8080) that shows graphs and tables for each container.
- API: It also exposes a JSON API so other tools can pull the same metrics.
Why does it matter?
- Performance troubleshooting: Quickly spot a container that’s hogging CPU or memory before it crashes your service.
- Capacity planning: See trends over time to decide when you need more resources or to right‑size containers.
- Cost control: In cloud environments, knowing exact usage helps avoid over‑provisioning and saves money.
- Automation: Metrics can feed alerts or auto‑scaling systems, making your infrastructure more resilient.
Where is it used?
- Development machines: Developers run cAdvisor locally to understand how their containers behave during testing.
- Production servers: Ops teams deploy cAdvisor on each host in a Kubernetes or Docker Swarm cluster to monitor all running pods/containers.
- Edge devices: Small IoT gateways that run containers can use cAdvisor for lightweight monitoring without a full monitoring stack.
- Educational labs: Teaching containers and monitoring concepts often includes cAdvisor as a simple example.
Good things about it
- Zero‑config start: Just run the Docker image and it begins collecting data immediately.
- Lightweight: Low CPU and memory overhead, suitable for even modest servers.
- Rich built‑in UI: No need to set up Grafana or other dashboards for basic visibility.
- Open source & community‑supported: Free to use, with regular updates from Google and contributors.
- Integrates easily: Works well with Prometheus, InfluxDB, and other monitoring stacks via its API.
Not-so-good things
- Limited long‑term storage: By default it only keeps recent data; you need extra tools for historic analysis.
- Scalability concerns: Running a separate cAdvisor per host can become cumbersome in very large clusters; centralized solutions may be preferred.
- Feature set is basic: It focuses on container metrics only; it doesn’t monitor host‑level services, logs, or application‑specific metrics.
- Security: Exposes a web UI and API on the host; you must secure access (firewall, auth proxy) to avoid exposing internal data.
- Deprecated in some contexts: In Kubernetes, the built‑in metrics-server and kube‑state‑metrics are often recommended over cAdvisor for cluster‑wide monitoring.