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.
Without monitoring, you find out about outages from users. With it, you find out from a graph, usually before users notice. With good monitoring, you also know which of your forty services caused it.
The three signals
Observability tooling collects three kinds of data. They answer different questions and cost very different amounts.
| Signal | What it is | Answers | Cost per event |
|---|---|---|---|
| Metrics | Numbers sampled over time: request rate, p99 latency, free disk | Is something wrong? Since when? How bad? | Almost zero; cost scales with the number of series, not traffic |
| Logs | Text or structured records, one per event | What exactly happened in this request? | Grows linearly with traffic |
| Traces | The path of one request through many services, with timings | Which 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/searchroute, 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.
Pull has some useful consequences:
- Prometheus knows when a target is down. A failed scrape is itself a
signal: the
upmetric becomes0. 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/metricsshows 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.
A common early mistake is treating Prometheus as an analytics database
and adding labels like user_id, email, or order_id "so we can
filter by them later." Each unique value creates a new time series.
Prometheus slows down and eventually runs out of memory. If you need
per-entity data, emit an event to a log or a database instead.
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.