Observability, Metrics, and Prometheus
From Traditional Monitoring to Observability
Traditional (Black-Box) Monitoring (slides 29–30)
(Source qualification: Printed slide 30 carries the heading “White-box monitoring”, while its text explicitly describes static up/down checks treating applications as black-boxes.)
- Purpose: Traditional Operations teams monitor overall system health across three metric categories:
- Network-related (e.g., endpoint is up and reachable).
- Machine / Infrastructure-related (e.g., disk consumption).
- Application-related (e.g., number of queries).
- Limitation: Up/down checks against static server targets treat applications as black boxes. Operators can verify whether a service is alive and check resource consumption, only detecting known problems after they are already occurring, with no insight into internal execution or root causes.
Why Microservices Require Observability (slide 31)
- Problem solved: In complex microservice architectures, many failures are “unknown unknowns”—novel bugs triggered only under rare combinations of load, latency, or partial failures that cannot be predicted ahead of time with static alert rules.
- Definition: Observability is a superset of monitoring that provides “highly granular insights into the behavior of systems along with rich context, perfect for debugging purposes.” Developers and operators can investigate runtime events after the fact to trace both effects and root causes.
The Three Pillars of Observability (slide 32)
| Pillar | What it captures | Primary role | Slide example / tool |
|---|---|---|---|
| Logs | Written discrete event records | Track what happened inside an application execution step-by-step | stdout streams -> FluentBit -> Elasticsearch / Loki |
| Metrics | Quantitative numerical measurements over time | Assess performance, throughput, errors, and resource consumption cheaply | OpenMetrics /metrics -> Prometheus |
| Traces | End-to-end request paths across distributed services | Follow one request hop-by-hop across microservices to pinpoint bottlenecks | Jaeger UI dependency graph (istio-ingressgateway -> service-a -> service-b…) |
Common confusion: Having one pillar is not full observability. Metrics tell you that latency spiked (symptom), Traces show which microservice hop slowed down (location), and Logs reveal why that service threw an exception (root cause).
Metrics Collection and OpenMetrics (slide 33)
- Mechanism: Each running process exposes only the instant value of internal metrics—either directly (e.g., on
http://localhost:3000/metrics) or through an ad-hoc exporter—to be scraped by a metric collector. - OpenMetrics: Originally introduced by Prometheus, OpenMetrics is the de-facto standard text exposition format, supporting four metric kinds:
- Counter: Cumulative value that only increases (or resets on restart), e.g.,
http_server_requests_total(1.0) andhttp_server_exceptions_total. - Gauge: Instantaneous value that can go up or down (e.g., memory used, active connections).
- Histogram: Counts observations into configurable buckets (
le="0.005",le="0.01", …,le="+Inf"), plus_sumand_count, shown in slide 33 forhttp_server_request_duration_seconds. - Summary: Similar to a histogram, computing streaming quantiles over a sliding window on the client side.
- Counter: Cumulative value that only increases (or resets on restart), e.g.,
Prometheus Architecture (slides 34–35)
Developed originally by SoundCloud, Prometheus is now a CNCF graduated project and the de-facto standard monitoring model on Kubernetes (also used by HPA for custom autoscaling metrics in Kubernetes Multi-Tenancy Quotas and Autoscaling).
Core internals and data flow (slide 35 diagram)
- Service Discovery (
kubernetes,file_sd): Automatically discovers Prometheus targets (applications or exporters) in dynamic container environments. - Pull-based Retrieval & TSDB: The Prometheus server’s Retrieval engine actively pulls (scrapes) metrics over HTTP from targets and stores them in its integrated Time-Series Database (
TSDB) on local HDD/SSD (with support for external DBs). - Short-lived Jobs exception (
Pushgateway): Because short-lived batch jobs may exit before Prometheus’s next scrape interval, those jobs push metrics at exit to a Pushgateway, which Prometheus then pulls from normally. - Querying & Visualization: Clients (Prometheus Web UI, Grafana, external API clients) query the
HTTP serverusing PromQL or the REST API. - Alerting: Prometheus evaluates alert rules and pushes alerts to Alertmanager, which routes notifications to PagerDuty, Email, or other receivers.
Retrieval
- Why is traditional black-box monitoring insufficient for microservice architectures compared to observability?
Black-box monitoring checks static targets for known failure symptoms (up/down, resource thresholds) after an outage begins. Complex microservices suffer from unpredictable unknown issues under specific conditions, requiring observability—a superset combining rich contextual logs, metrics, and traces to diagnose root causes. - A user reports that checkout occasionally takes 8 seconds instead of 200 ms. How do Metrics, Traces, and Logs work together to debug it?
Metrics (e.g., an OpenMetrics latency Histogram) confirm when and how often the 8 s latency spike occurs; a Trace (e.g., Jaeger) follows a slow request across microservices to identify the exact slow service hop; Logs from that service explain the internal error, retry, or query failure causing the delay. - Why does Prometheus primarily use a pull model, and when is
Pushgatewayused instead?
With Service Discovery (kubernetes,file_sd), a pull model lets Prometheus control scrape frequency and immediately detect dead targets without every app needing to know where the collector lives.Pushgatewaybridges the gap for short-lived jobs that finish before a scheduled scrape can reach them, letting them push final metrics on exit for Prometheus to pull later.
Source: Lecture 12 - Cloud Native Applications and the 12-Factor App, PDF pages 27–34 (printed slides 28–35).