Learn Labs
Why Observability

Why Monitoring

Metrics, logs, traces, pull vs push, and when Prometheus is the wrong tool

Every system you've built in this repo so far, Postgres and ClickHouse, has been something you query. Monitoring flips that around: instead of asking a system a question when you think of one, you record a small set of numbers about it all the time, so that when something goes wrong you can look back and see when it started, where, and how bad it is.

The three signals

Observability tooling collects three kinds of data. They answer different questions and cost very different amounts.

SignalWhat it isAnswersCost per event
MetricsNumbers sampled over time: request rate, p99 latency, free diskIs something wrong? Since when? How bad?Almost zero; cost scales with the number of series, not traffic
LogsText or structured records, one per eventWhat exactly happened in this request?Grows linearly with traffic
TracesThe path of one request through many services, with timingsWhich hop was slow?High, so usually sampled

The usual workflow runs in that order: a metric alert fires, a trace shows which service is slow, and that service's logs show why. Prometheus and Grafana own the first step, and Grafana also displays the other two (see Logs & Traces).

The key property of metrics: a counter of HTTP requests costs the same whether you serve 10 requests a second or 10 million. Prometheus doesn't store requests. It stores a number that goes up, sampled every 15 seconds. That's why metrics are the only signal you can afford to keep for everything.

Monitoring vs observability

The two words get used loosely. The useful distinction:

  • Monitoring answers questions you knew to ask in advance. "Alert me if the error rate goes above 1%."
  • Observability is being able to answer questions you didn't predict, by slicing your data in new ways during an incident. "Errors went up, but only for the /api/search route, only on version 1.4.0."

Labels are what make Prometheus metrics useful for both. A request counter with route, status, and version labels can answer questions nobody wrote an alert for.

Pull vs push

Most metrics systems (StatsD, Graphite, Datadog's agent, OpenTelemetry's default) are push-based: the application sends its numbers to a collector. Prometheus is pull-based. Each application exposes its current numbers on an HTTP endpoint, usually /metrics, and Prometheus fetches (scrapes) them on a schedule.

scrapePrometheusGET /metrics every 15 sdemo-app:8080up = 1node-exporterup = 1clickhouse:9363up = 0 (refused)TSDBsamples + uparrows point at what Prometheus fetches: a dead target is noticed, not silent

Pull has some useful consequences:

  • Prometheus knows when a target is down. A failed scrape is itself a signal: the up metric becomes 0. With push, a dead app and a quiet app look the same: no data arrives.
  • The app stays simple. It just keeps counters in memory and serialises them on request. No client-side buffering, retries, or collector address.
  • You can scrape anything from your laptop. curl localhost:8080/metrics shows exactly what Prometheus will see.
  • Prometheus controls the load. A traffic spike in the app doesn't turn into a spike of metric writes.

The cost: Prometheus must be able to reach every target. That's awkward for short-lived batch jobs (they finish before the next scrape) and for targets behind NAT. The Pushgateway and remote write exist for those cases.

Where Prometheus is the wrong tool

Prometheus deliberately trades accuracy for cheapness. Samples are taken every few seconds, rate() extrapolates, and percentiles are estimates. That's fine for "is the service healthy?" and wrong for:

  • Billing or anything that must be exact. If you need to count every request precisely, write events to a database (ClickHouse is a good fit) and sum them.
  • Per-user or per-request data. A label with one value per user ID creates one series per user. That's a cardinality explosion, covered in Cardinality Management.
  • Long-term analytics. A single Prometheus keeps weeks of data, not years. Long-term storage needs another layer.
  • Event search. "Show me the request that failed at 14:02:31" is a log or trace question.

What you'll build

By the end of this module the stack in prometheus/compose_prod.yaml will be monitoring:

  • an instrumented demo service with request rate, errors, and latency histograms, plus a knob to break it on purpose
  • the host's CPU, memory, and disk (node_exporter)
  • the PostgreSQL module (postgres_exporter)
  • the ClickHouse module (built-in endpoint)
  • the monitoring stack itself

You'll also have SLO-based alerts that are unit tested, routed by Alertmanager, and dashboards stored as code. Start with Docker & Setup.

On this page