Container Metrics & Monitoring (cAdvisor, Prometheus, Grafana)
Collect container metrics with cAdvisor/Prometheus and visualize in Grafana.
In plain words
Alert on saturation, throttling, OOM, restarts and capacity with application SLOs beside container resource use.
Think of it like…
Metrics are the container’s industrial gauges: Prometheus is the recorder and Grafana is the control-room board, but none can diagnose a missing sensor.
Where you’ve seen it
In practice, rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limits is the concrete move for this job: collect container metrics with cAdvisor/Prometheus and visualize in Grafana. The release is not accepted until load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas confirms the result.
Words you’ll hear
- cAdvisor
- The implementation control in
rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limitsfor collect container metrics with cAdvisor/Prometheus and visualize in Grafana. - Prometheus
- The result to observe with
load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas, rather than infer from a successful command alone. - Grafana
- The production boundary exposed when alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity.
Visual diagram
Theory & deep dive
cAdvisor control path
The concrete mechanism is rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limits. The observable result is load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas; if those disagree, inspect the runtime evidence before changing unrelated settings.
Collect container metrics with cAdvisor/Prometheus and visualize in Grafana. Keep cAdvisor, Prometheus and Grafana in the same deployment record so the intent and the observed state cannot drift apart.
rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limits
load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas, not with command success alone.Grafana failure boundary
Counter values must be converted with rate(), and CPU quota percentages are relative to configured limits. High-cardinality labels and dead-container series can exhaust Prometheus, while container_memory_usage_bytes includes cache that does not always imply app demand. The narrow failure to design for is alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity.
Accept this compromise explicitly: cAdvisor plus Prometheus gives infrastructure facts; application tracing and logs explain whether saturation is normal demand or a code regression. The controlled check-load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas-also identifies the point where a different design is safer.
Exercise this failure safely: alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: Counter values must be converted with rate(), and CPU quota percentages are relative to configured limits. High-cardinality labels and dead-container series can exhaust Prometheus, while container_memory_usage_bytes includes cache that does not always imply app demand.
- Intent
- cAdvisor
When to use it & trade-offs
What it is
cAdvisor exposes cgroup/container CPU, memory, filesystem and network counters; Prometheus scrapes and stores time series, and Grafana queries them. Effective dashboards use rates, working-set memory and restart/limit signals rather than instantaneous CPU percentage alone.
Why it matters: Counter values must be converted with rate(), and CPU quota percentages are relative to configured limits. High-cardinality labels and dead-container series can exhaust Prometheus, while container_memory_usage_bytes includes cache that does not always imply app demand.
When to reach for it
- The fit is strongest for this job: collect container metrics with cAdvisor/Prometheus and visualize in Grafana. Pair it with
load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltasin the runbook. - Production cAdvisor changes should make Prometheus observable through
rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limits, rather than trusting the runtime default. - Keep a rollback example for the case where alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity.
When to avoid or be careful
- Do not accept command success while the system can still fail by alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity.
- Avoid erasing Grafana protection merely to dodge this cost: “cAdvisor plus Prometheus gives infrastructure facts; application tracing and logs explain whether saturation is normal demand or a code regression”.
- Do not replace the evidence path-
load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas-with a screenshot or a mutable tag.
rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limits: practical choices
Strengths: cAdvisor exposes cgroup/container CPU, memory, filesystem and network counters; Prometheus scrapes and stores time series, and Grafana queries them. Effective dashboards use rates, working-set memory and restart/limit signals rather than instantaneous CPU percentage alone.
Watch out: cAdvisor plus Prometheus gives infrastructure facts; application tracing and logs explain whether saturation is normal demand or a code regression.
Strengths: It can begin with rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limits and fewer surrounding controls.
Watch out: It silently accepts alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity, which makes the result hard to reproduce after promotion.
Strengths: Counter values must be converted with rate(), and CPU quota percentages are relative to configured limits. High-cardinality labels and dead-container series can exhaust Prometheus, while container_memory_usage_bytes includes cache that does not always imply app demand.
Watch out: The platform adds an ownership and debugging layer; retain load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas as the direct check.
Interview signals & numbers to know
When this topic comes up
- rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limits
- load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas
- Failure signature: alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity
- Trade-off: cAdvisor plus Prometheus gives infrastructure facts; application tracing and logs explain whether saturation is normal demand or a code regression.
Benchmarks & rules of thumb
- 5 minutes
- useful scrape/rate window for short changes
- 15 seconds
- common but configurable Prometheus scrape interval
- 2 restarts/samples
- alert should focus on deltas not raw cumulative numbers
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limitsas proof and skippingload-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas. - Alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity
- Optimizing cAdvisor without accepting that cAdvisor plus Prometheus gives infrastructure facts; application tracing and logs explain whether saturation is normal demand or a code regression.
Likely interviewer follow-ups
- Why does
rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limitsaddress cAdvisor here rather than through application code? - How would you distinguish healthy Prometheus from the failure “alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity” using
load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas? - When would this trade-off-“cAdvisor plus Prometheus gives infrastructure facts; application tracing and logs explain whether saturation is normal demand or a code regression”-justify a different Grafana design?
rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limits-and one proof-load-test api, confirm CPU throttling and working-set alerts, restart it, and see container_last_seen/restart deltas. Then name the boundary: alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Container Metrics & Monitoring (cAdvisor, Prometheus, Grafana) with generative AI interview Q&A and hands-on practice.