Topic 2 of 5 · 4 min read
Choosing metrics that reflect users
Goal: Choose the metrics for a service using the golden signals and spot the label that would explode metric cardinality.
Measure what users feel (how often requests happen, how many fail, how long they take) and keep every label to a small, fixed set of values. A dashboard full of CPU graphs can look healthy while checkout is broken.
Check yourself · 1 of 3
Which set is the RED method for a request-driven service?
Why it matters
Metrics are cheap, numeric time series. They answer "is it bad right now, and since when?" faster than logs. But only if they measure the right things. The Google SRE book names four golden signals: latency, traffic, errors and saturation. For a request-driven service, the RED method is the short form: Rate, Errors, Duration.
How to do it
- Count requests with a counter, labelled by route and status class (
2xx,4xx,5xx). - Count errors the same way, so error rate is errors divided by requests.
- Record duration in a histogram, not an average. An average of 200 ms can hide that 1 request in 20 takes 4 seconds. Alert and report on p95 and p99, which Prometheus computes from histogram buckets.
- Add saturation for the thing that runs out first: queue depth, connection pool use, memory.
- Control cardinality. Each distinct combination of label values creates a new time series that the metrics store must keep. Labels must be bounded: route template, method, status class, region. Never user id, email, full URL, request id or an error message. The Prometheus naming guide warns about exactly this.
Before and after
// Before: one series per user and per raw URL
requests.inc({ userId: user.id, url: req.url });
// After: a bounded set of labels
requests.inc({ route: "/orders/:id", method: req.method, status: "2xx" });
With 50,000 users and 400 URLs the first form can create millions of series, slow the store down and raise the bill. The second creates a few dozen. Per-user detail belongs in logs or traces.
What goes wrong
- Averages only. The mean hides the slow tail that real users hit.
- Raw path as a label.
/orders/123,/orders/124each become a series. - Measuring causes, not symptoms. CPU at 70 percent says nothing about whether users are failing.
- No metric for model calls. Agent features need request count, error rate, latency and token counts per model, with the model name as a label.
Examples
Latency histogram
const duration = new Histogram({
name: "http_request_duration_seconds",
help: "Request duration",
labelNames: ["route", "method", "status"],
buckets: [0.05, 0.1, 0.25, 0.5, 1, 2.5, 5],
});
Buckets let the backend estimate p95 across all instances. An average gauge cannot be combined that way.
Spotting the exploding label
A teammate adds model_calls_total{prompt="..."} so they can see which prompts are slow. Prompts are free text, so every call creates a new series. Replace it with {model, status} and log the prompt hash with the request id instead.
Key points
- Start from the golden signals: latency, traffic, errors and saturation; RED is the short form for request services.
- Record duration in a histogram and read p95 or p99; an average hides the slow tail.
- Every unique label combination is a separate time series, so labels must come from a small fixed set.
- Never use user ids, emails, raw URLs or error messages as metric labels; put that detail in logs or traces.
- Label by route template, such as /orders/:id, not by the concrete path.
Common mistakes
- Dashboarding averages and then missing a slow tail that affects 5 percent of users.
- Labelling with user id, order id or the raw URL because it is handy while debugging.
- Tracking only infrastructure (CPU, memory) and nothing about request success.
- Adding a metric per feature without a bounded naming scheme, so nobody can find anything.
Check yourself · 2 of 3
Why report p99 latency rather than only the average?
Check yourself · 3 of 3
Which label on a request counter is most likely to explode the number of time series?
Practice items, not counted towards your mastery.
Start here
- OpenTelemetry documentation (opens in a new tab)DocsFree
The vendor-neutral standard for traces, metrics and logs, with concepts and language guides.
- Monitoring Distributed Systems (Google SRE Book) (opens in a new tab)BookFree
Defines the four golden signals and explains why to page on symptoms and use percentiles.
- Alerting on SLOs (Google SRE Workbook) (opens in a new tab)BookFree
Worked burn-rate alerts that turn an SLO into pages that matter.
More for this topic
- Metric and label naming (Prometheus) (opens in a new tab)DocsFree
Explains why every distinct label value creates a new time series and what to avoid as a label.
- Histograms and summaries (Prometheus) (opens in a new tab)DocsFree
Shows how to measure latency percentiles with histogram buckets instead of averages.