Observability

Prometheus

A monitoring system with a time series database: it scrapes metrics in a pull model and offers the PromQL query language.

What it is

Prometheus was created at SoundCloud in 2012. It later became the second CNCF project after Kubernetes and reached graduated status (2018). It is the metrics standard in the Kubernetes world.

The pull model: Prometheus polls the /metrics HTTP endpoints of your services at a set interval and stores values as time series with labels. Short-lived jobs can use the Pushgateway.

Data is read with PromQL, and alert rules are built on top of it. Notifications are sent by a separate Alertmanager. For graphs you usually plug in Grafana.

Use it when

  • Monitoring Kubernetes and microservices with dynamic target discovery.
  • You need time series metrics: latency, error rate, load.
  • You want alerts based on a flexible query language.
  • You want an open source solution with no vendor lock-in.

Avoid it when

  • You need logs or traces: Loki, Elasticsearch and Jaeger are for those.
  • You need long-term storage across many clusters without extra components (Thanos, Mimir).
  • You need 100% exact event accounting such as billing: metrics are aggregated and sampled.

Key concepts

Metric types
Counter (only grows), Gauge (goes up and down), Histogram and Summary (distributions such as latency).
Labels
Key-value pairs that slice a metric (method, path, status). Too many unique values cause a cardinality problem.
Scrape
Polling a /metrics endpoint on a schedule, with targets defined in config or discovered automatically.
PromQL
A time series query language: rate(), sum by(), histogram_quantile().
Alertmanager
Groups, deduplicates and routes alerts to Slack, email or PagerDuty.

Example

A scrape config and a sample PromQL query in a comment.

Interview questions

  1. 1. How does the Prometheus pull model differ from push?

    In pull, Prometheus polls services itself, so it is easy to see that a target is down and you do not configure each service with a collector address. Push suits short-lived jobs, which is what the Pushgateway is for.

  2. 2. What metric types exist?

    A Counter only grows (request count), a Gauge can move both ways (memory in use), Histogram and Summary describe the distribution of values like latency. For counters you usually take rate().

  3. 3. What is label cardinality and why is it a problem?

    It is the number of unique combinations of label values. A label with unbounded values, such as user ID, creates millions of series and exhausts memory and disk.

  4. 4. Why Alertmanager if Prometheus already has alerts?

    Prometheus only evaluates rules and generates alerts. Alertmanager groups them, removes duplicates, stays silent during maintenance and sends them to the right channels.

Interview questions from the bank

Comparisons with this technology

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).