StoicBuilder

HandbookXII the SpeculaMetrics

XIIthe Specula, Watch production

Metrics

1 min readUpdated 28 November

In plain words

Metrics are numbers your services record continuously, such as requests per second, error count and response time, stored as time series so you can graph trends and alert on them cheaply.

Where you see it

A Grafana dashboard for Harbor's API with four panels: requests per second, error rate, p95 latency and the build queue's length. In Harbor's setup, Prometheus collects the numbers from each service's /metrics endpoint every 15 seconds and keeps the history.

Grafana, PromQLconfig
# p95 checkout latency over the last 5 minuteshistogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket{route="/api/checkout"}[5m]))) # share of requests that failedsum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m]))
A percentile from a histogram, and an error ratio from counters. Neither needs a single log line.

What goes wrong

  1. Watching the average

    An average of 200 ms can hide one request in twenty taking four seconds. Track percentiles such as p95 and p99, which show what your slowest users live with.

  2. A label for every user

    Each new label value creates a new time series, so user or order IDs as labels make the metrics store slow and expensive. Keep labels to small sets like route, method and status; put IDs in logs and traces.

    http_requests_total{route="/api/checkout", user_id="u_8812"}
  3. Measuring the machine, not the user

    CPU and memory can look calm while checkout fails for every customer. Start with what users feel: the rate, errors and duration of each important route.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Add Prometheus metrics to each service using the RED pattern: a counter for requests and errors and a histogram for duration, labelled only by route, method and status code. Expose them on /metrics, and never use user IDs, emails or order IDs as labels.

Quick check

Sign in to earn +10 XP for it

Harbor's dashboard shows an average API response time of 180 ms, yet support keeps hearing that checkout hangs. What should you look at next?

Got a prompt that touches metrics?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.