Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 132/ 160
07. CI/CD, Registries & Production Operations

Container Metrics & Monitoring (cAdvisor, Prometheus, Grafana)

Collect container metrics with cAdvisor/Prometheus and visualize in Grafana.

IntermediatecAdvisor · Prometheus3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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_limits for 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

Loading interactive 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.

Concrete cAdvisor setup

rate(container_cpu_usage_seconds_total{container="api"}[5m]); container_memory_working_set_bytes / kube_pod_container_resource_limits

Key takeaway: Prove Prometheus with 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.

Deliberate failure test

Exercise this failure safely: alerting raw cumulative counters, or aggregating all workloads without respecting cgroup/namespace identity.

Key takeaway: cAdvisor plus Prometheus gives infrastructure facts; application tracing and logs explain whether saturation is normal demand or a code regression.

How it works, step by step

Step 1 of 4
Design

1. 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.

Alert on saturation, throttling, OOM, restarts and capacity with application SLOs beside container resource use.
Key numbers at this step
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 deltas in 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

Explicit cAdvisor
Best for: Collect container metrics with cAdvisor/Prometheus and visualize in Grafana, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Prometheus experiments with low blast radius.

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.

Managed Grafana
Best for: Teams that centralize Grafana policy across many workloads.

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_limits as proof and skipping load-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_limits address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Centralized Log Aggregation (Grafana Loki, ELK Stack, Promtail)
Next topic
Graceful Shutdowns, SIGTERM vs SIGKILL & Signal Handling