Metrics
Request rate, error rate, latency percentiles and saturation: the four signals, and why the average hides the slow requests.
The dashboard gauges: how busy, how fast, how many things are going wrong.
That is what metrics are. A driver does not read a log of every turn of the engine. They glance at speed, fuel and temperature, and know at once whether something is off.
How it works
Metrics answer: how much, and how often? They are numbers sampled over time, cheap to store and quick to read.
CPU usage
Memory usage
Request count
Error rate
Latency
Database connections
Cache hit ratio
For an API, the core set is small.
Requests per second
Error rate
P50 latency
P95 latency
P99 latency
These map onto the four golden signals: latency, traffic, errors and saturation. Latency is how long requests take. Traffic is how much demand there is. Errors is how many requests fail. Saturation is how full the system is, such as CPU, memory, connections or queue length. If you can see those four for each service, you can answer most first questions in an incident.
Why percentiles matter
Average latency hides outliers.
99 requests at 50 ms
1 request at 10 seconds
The average looks acceptable. P99 shows the problem. Track percentiles, not just averages.
- P50 is the typical request.
- P95 is what one user in twenty sees.
- P99 is where a struggling dependency shows up first.
Kinds of metric
- Counter. Only goes up, such as requests served. You read it as a rate.
- Gauge. Goes up and down, such as open connections or queue length.
- Histogram. Records how values are distributed, which is how percentiles are computed.
Labels and their cost
A label splits a metric by a dimension, such as route or status code. It is very useful, and it multiplies storage. A label with many possible values, such as a user id, creates a separate series for each one. Keep labels to a small, known set, and put high-cardinality detail in logs or traces instead.
From a metric to an alert
A metric becomes useful when it drives an alert: error rate above a threshold for five minutes, or P99 above a limit. See observability for how alerts, logs and traces fit together.
Choosing a first dashboard
A first dashboard needs one row per signal: traffic, errors, latency percentiles and saturation. Put the user-facing numbers at the top, and the infrastructure numbers below them. Add the numbers for any queue, such as the age of the oldest waiting job, and for any external dependency, such as the error rate of calls to a payment or model provider. A dashboard that answers is it us or is it them saves the first ten minutes of an incident.
Where I used it
I haven't shipped this in a public project yet, and I have no figures to show.
The nearest thing in my work is a design choice in POS SaaS. The design puts the age of the oldest pending invoice on a screen, because queue depth can be large and healthy while age cannot. That is a decision about which number to watch. POS is early-stage, so it is a design and not a measured result.
Trade-offs
- A metric tells you that, not why. It shows an error rate climbing. A log or a trace explains it.
- Cardinality. Too many label values make a metrics system slow and costly.
- Thresholds are guesses at first. Alerts set from nothing are either noisy or silent. Adjust them from real traffic.
- Averages mislead. A dashboard of means can look fine during a slow period.
- Dashboards decay. A wall of charts that nobody checks gives a false sense of safety. Keep the ones that someone uses.
A useful rule: every production service needs request rate, error rate and latency percentiles, plus one saturation number. Add more only when an incident shows you the gap.