Metrics pipeline and dashboards
Separate resource metrics from application metrics
Resource metrics describe CPU and memory consumption. The kubelet exposes resource usage; an installed metrics-server gathers it and serves the resource Metrics API, used by kubectl top and resource-based autoscaling. This is not a general historical monitoring database. Application metrics instead describe requests, errors, queues and latency. They require instrumentation and a suitable collection path. Low CPU does not imply good latency. An absent sample must be investigated, not replaced with zero.
kubectl --kubeconfig ./lab.kubeconfig --context observability-lab -n bookstore-demo top pods# Requires a functioning resource Metrics API; example is not executed.Build a metrics pipeline with clear ownership
Prometheus can scrape instrumented endpoints at configured intervals, store time series and evaluate PromQL queries. kube-state-metrics translates Kubernetes object state into metrics, such as desired and available replicas; node exporter reports host operating-system and hardware measurements. Kubelet endpoints can expose container and resource measurements, including cAdvisor metrics where supported. These components are optional or environment-dependent; verify endpoint access, versions and platform restrictions. Grafana visualizes and queries configured data sources, not a substitute for collecting and storing samples.
Application /metrics ──┐kube-state-metrics ─────┼─> Prometheus ─> Grafananode / kubelet metrics ─┘Separate path: kubelet -> metrics-server -> Metrics APICalculate a rate, not a counter total
A counter usually rises as events accumulate and can reset when its process restarts. A gauge can move in either direction, such as queue depth. If a counter increases from 120 to 180 over 60 seconds with no reset, its simple endpoint rate is 1 request per second. Prometheus rate estimates a per-second increase over a range and handles resets and extrapolation; the offline arithmetic is deliberately not a PromQL implementation. Apply rate before aggregating counters across replicas so resets can be detected per series. The names below are proposed instrument names, not built-in Kubernetes metrics.
sum by (service) (rate(bookstore_http_requests_total[5m]))# Query example only: needs a populated Prometheus instance.Interpret classic histogram buckets
A classic latency histogram records cumulative bucket counters for upper boundaries. For a fixed interval, 80 of 100 observations at or below 0.3 seconds means 80% meet that boundary. It does not reveal the exact duration of each request. Preserve the le label when combining classic buckets for histogram_quantile; its estimate depends on bucket boundaries and data. Avoid averaging per-instance percentiles. Use compatible bucket schemes, keep units explicit, and inspect sample counts for low traffic.
histogram_quantile(0.95, sum by (service, le) (rate(bookstore_http_request_duration_seconds_bucket[5m])))# Classic histogram query; not executed.Control cardinality and dashboard gaps
A time series is distinguished by metric name and its label set. Three services, two methods and five status classes can yield up to 30 combinations per metric before other labels or histogram buckets. An unbounded request ID or raw URL multiplies cost and makes aggregation harder. Use bounded route templates and status classes. Choose scrape interval and retention according to diagnostic resolution, volume and cost; shorter intervals generate more samples but do not guarantee accurate instrumentation. Display gaps and query errors explicitly. Build the dashboard from the synthetic series in lab-fixtures/observability/metric-cases.json and histogram.json; do not claim these are production measurements.
Further reading and practice
Offline lab: lab-fixtures/observability/README.md. These examples are synthetic; no cluster execution was tested. Selected official sources are listed in the chapter review.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Metrics pipeline and dashboards — knowledge check
Interpret synthetic observability evidence.
Which component supplies the usual resource Metrics API for kubectl top?
Which source reports desired replica state from Kubernetes objects?
A counter rises from 120 to 180 in 60 seconds without reset. What is the endpoint rate?
80 of 100 requests are in a cumulative 0.3-second bucket. What is known?
Which label should normally be avoided on a request counter?