Scripts2026年4月16日·1 分钟阅读

cAdvisor — Real-Time Container Resource Monitoring by Google

Analyze container resource usage and performance with Google's cAdvisor. Native Docker support, Prometheus metrics export, and zero-config deployment for production container monitoring.

Introduction

cAdvisor (Container Advisor) is a running daemon that collects, aggregates, processes, and exports information about running containers. Developed by Google, it provides container users with an understanding of the resource usage and performance characteristics of their running containers. It is a core component in Kubernetes's monitoring stack and works natively with Docker, containerd, and other runtimes.

What cAdvisor Does

  • Collects CPU, memory, filesystem, and network usage for every running container automatically
  • Provides a built-in web UI dashboard showing real-time container statistics
  • Exports metrics in Prometheus format at /metrics for scraping
  • Tracks container lifecycle events including creation, start, stop, and OOM kills
  • Supports per-container resource isolation monitoring via cgroups v1 and v2

Architecture Overview

cAdvisor runs as a single Go binary or container that hooks into the Linux kernel's cgroup filesystem and /proc. It discovers containers via the container runtime socket, reads resource counters from cgroups and procfs, and maintains an in-memory ring buffer of recent stats. A built-in HTTP server exposes a REST API, a Prometheus metrics endpoint, and an optional web UI. In Kubernetes, cAdvisor is embedded in the kubelet on every node.

Self-Hosting & Configuration

  • Run as a Docker container with host volume mounts for /sys, /var/run, and /var/lib/docker
  • Deploy as a DaemonSet in Kubernetes for cluster-wide container monitoring
  • Configure storage drivers with --storage_driver flag (stdout, Elasticsearch, InfluxDB)
  • Adjust collection interval with --housekeeping_interval (default 1s) for tuning
  • Use --docker_only=true to limit monitoring scope to Docker containers only

Key Features

  • Zero-configuration container discovery with automatic detection of new containers
  • Sub-second metric resolution for CPU, memory, disk I/O, and network per container
  • Native Prometheus endpoint eliminates the need for separate metric exporters
  • Built-in web dashboard for quick debugging without external tools
  • Tiny memory footprint suitable for resource-constrained edge and IoT nodes

Comparison with Similar Tools

  • Prometheus Node Exporter — host-level metrics only; cAdvisor adds per-container granularity
  • Datadog Agent — commercial SaaS with richer dashboards; cAdvisor is free and self-hosted
  • ctop — interactive TUI for Docker; cAdvisor adds persistence, API, and Prometheus export
  • Sysdig — deeper kernel tracing with eBPF; cAdvisor is lighter and built into kubelet

FAQ

Q: Is cAdvisor already included in Kubernetes? A: Yes. The kubelet embeds cAdvisor, so every Kubernetes node collects container metrics automatically. You only need standalone cAdvisor for non-Kubernetes Docker hosts.

Q: Does cAdvisor support cgroups v2? A: Yes. Recent versions fully support cgroups v2, which is the default on modern Linux distributions like Ubuntu 22.04+ and Fedora 31+.

Q: How much overhead does cAdvisor add? A: Minimal — typically under 50 MB of RAM and negligible CPU. The housekeeping interval can be tuned to reduce overhead further.

Q: Can cAdvisor monitor non-Docker containers? A: Yes. It supports containerd, CRI-O, and raw cgroup-based process monitoring, covering most container runtimes.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产