Skip to content

16 min read

Metrics with Prometheus and Grafana

In one sentence: A metric is a number measured over time: how many requests arrive, how many fail and how long they take. The shop sends them with OpenTelemetry to Prometheus, which keeps them, and Grafana draws them on a dashboard that tells you at a glance whether something is wrong.

What you will learn

  • Choose between a counter, a gauge and a histogram for what you want to measure.
  • Watch an API with RED and get its p99 from a histogram, knowing what that number doesn’t know.
  • Write PromQL queries with rate, sum by and histogram_quantile, and read their result.
  • Choose labels with few values, and explain why an id, a URL or an email aren’t.

Before you start, read: 04-traces.md phase-9/00-introduction.md

Imagine someone writes: “the shop is slow.” In lesson 4 you learned to open a request’s trace and see where the time went. But which one do you open? In the ten seconds of that lesson’s Load testAn experiment in which a program sends many requests in a row to your server to measure how many it can take and how long it takes to answer. It tells you where the limit is before your users find it.Go to definition, the shop answered 68,000 requests.

A trace tells about one request. To know whether the shop is slow, you need numbers that sum them all up: how many arrive per second, how many fail, how long the slowest take. In Phase 9 you measured them once, from outside, with autocannon. Now the shop measures them itself, all the time, from inside.

The analogy

Your home’s electricity meter only goes up: it marks the kilowatt-hours used since it was installed. That number, alone, says little. What matters is how much it went up between two readings: that’s what you pay. And if you divide it by the days, you know how much you use per day.

Next to it, the display of the power you’re using right now goes up and down: you turn on the oven, and it jumps.

Where the analogy breaks down

  • The electricity meter never goes back to zero. A program’s does, every time it restarts; PrometheusA program that asks your server for its metrics every few seconds, stores them with their time and lets you query them with its own language, PromQL. It is the most widely used metrics store alongside Grafana.Go to definition notices and doesn’t take it for a drop.
  • Electricity is read once a month. Prometheus receives a value every few seconds and, between two, estimates: that’s why three payments can come out as “4.42.”
  • Neither of the two says how long something took. For that you need a third type, the histogram.

This is what Prometheus keeps about paid orders, asked through its API after four payments:

{"metric":{"__name__":"shop_orders_paid_total","job":"shop-api"},"value":"4"}

A name, some labels (job="shop-api") and a value. Every 5 seconds, the API sends it again, and Prometheus writes it down with its time. That list of values with times is a time series, and each combination of name and labels is a different series.

job is who sends the MetricA number measured over time, like requests per second or the milliseconds a response takes. It weighs very little, so it is good for seeing trends and triggering an alert, although it does not say which request failed.Go to definition: lesson 4’s OTEL_SERVICE_NAME, shop-api or shop-worker.

Type How it moves In the shop What you look at
CounterA metric that only goes up, like the number of requests served since the program started. What matters is not its value but how fast it grows per second. If the program restarts, it goes back to zero.Go to definition Only goes up shop_orders_paid_total, the requests How much it goes up per second or per minute
GaugeA metric that goes up and down, like open connections or jobs waiting in a queue. Its value right now already says something, unlike a counter.Go to definition Goes up and down shop_queue_waiting, the jobs waiting in the queue What it’s worth now
HistogramA metric that counts how many measurements fall into each range, for example how many responses took under 100 ms, under 500 ms and under a second. It is used to work out percentiles without storing every measurement.Go to definition Counts measurements by buckets http_server_request_duration_seconds, how long each request takes The PercentileA number that says what share of the measurements falls below it. If the 99th percentile of the responses is 400 ms, 99% of the requests took 400 ms or less and only one in a hundred took longer. It shows the slow cases that an average hides.Go to definition

The shop’s own two counters are in src/metrics.ts:

src/metrics.ts
// A counter only goes up: 1 is added every time something happens. Prometheus adds _total to the
// name and changes the dots to underscores: shop_orders_paid_total.
export const metrics = {
// An order that really became paid (v2.ts). A repeated event, or a payment for a cancelled order,
// changes nothing and doesn't count.
ordersPaid: meter.createCounter('shop.orders.paid', {
description: 'Orders that became paid',
}),
// A response that doesn't have the shape the contract promises (contract-responses.ts). Attribute
// route: the contract's template (/orders/{id}).
responsesOutsideContract: meter.createCounter('shop.responses.outside_contract', {
description: "Responses that don't meet the API's contract",
}),
};
  • The name has dots (shop.orders.paid), as OpenTelemetry asks; Prometheus changes them to underscores and adds _total.
  • A payment counts once. In src/v2.ts, metrics.ordersPaid.add(1) goes after the COMMIT and only if the order really became paid: a repeated event or the payment of a canceled order don’t add up.
  • The one for responses outside the contract from lesson 3 carries a label, route, with the route’s template.

The gauge, shop.queue.waiting, doesn’t keep anything: every time the SDK collects the metrics, it asks the queue how many jobs are waiting, with 2 seconds at most. If Redis doesn’t answer, it observes nothing. And even so the graph isn’t cut: the SDK keeps sending the last value it saw. With Redis frozen, the line stays flat, as if nothing were wrong. A flat line isn’t always a healthy line.

@hono/otel, the one that creates each request’s span in lesson 4, also writes down how long it took in a histogram. In Prometheus it’s three series:

http_server_request_duration_seconds_bucket
http_server_request_duration_seconds_count
http_server_request_duration_seconds_sum
  • _count: how many requests, a counter.
  • _sum: how many seconds they took altogether.
  • _bucket: how many took at most each limit, the le label (less or equal): 5 ms, 10 ms, 25 ms, 50 ms… up to 10 s. Each bucket includes the ones before it.

The labels: http_route, the route’s template; http_request_method, the method, and http_response_status_code, the code.

RED for what’s asked of you, USE for what holds you up

Section titled “RED for what’s asked of you, USE for what holds you up”

The RED methodRED stands for Rate, Errors, Duration.A recipe for watching a service with just three metrics: how many requests arrive (Rate), how many fail (Errors) and how long they take (Duration). If any of the three goes wrong, something is happening to the people using your API.Go to definition watches a service with three questions: how many requests arrive (Rate), how many fail (Errors) and how long they take (Duration). All three come from the same histogram: the first two from _count, the third from _bucket. They’re the shop’s top three panels.

For resources (CPU, memory, a queue) there’s the USE method: how much they’re used (Utilization), how much work is waiting (Saturation) and how many errors they give (Errors). shop_queue_waiting is saturation: work waiting for a worker that can’t keep up.

PromQLThe language used to query Prometheus metrics. With one line you can ask for, for example, requests per second over the last five minutes or the 99th percentile of latency.Go to definition is the language for asking Prometheus. Four queries cover almost the whole shop dashboard:

  1. http_server_request_duration_seconds_count{job="shop-api",http_route="/v2/products"}: the counter as it is, with the labels that have to match between braces. A number that only grows.
  2. rate(…[1m]): how much it went up per second, on average, in the last minute. This is already requests per second.
  3. sum by (http_route) (rate(…[1m])): adds up the series that only differ in other labels (the method, the code, each copy of the API) and leaves one per route. It’s the “Requests per second, by route” panel.
  4. histogram_quantile(0.99, sum by (le, http_route) (rate(…_bucket[1m]))): each route’s 99th percentile, from the buckets.

One more, increase(…[1m]), is rate times the window’s seconds: how much it went up in a minute. The “Paid orders per minute” panel is sum(increase(shop_orders_paid_total[1m])).

Each different combination of labels is a series, and Prometheus keeps every one. Route, method and code give a few dozen: few. With the whole URL (/v2/products/1, /v2/products/2…) there would be one per product; with the order’s id or the customer’s email, one per order or per person, endlessly.

That’s CardinalityThe number of different values a metric’s label can take. Labelling with the route has few values; labelling with the user id has millions, and each one creates a new series that fills up memory.Go to definition, and the kind that grows without limit fills Prometheus’s memory. That’s why @hono/otel uses the template (/v2/products/:id). An email is also personal data: lesson 4’s rule for spans applies to labels.

Usually Prometheus goes and fetches the metrics from each service every few seconds (scrape). In the shop, the API pushes: the OpenTelemetry SDK sends them over OTLP every 5 seconds to OTEL_EXPORTER_OTLP_METRICS_ENDPOINT:

compose.observability.yaml
# Prometheus, pinned by its digest: it keeps the metrics, and receives them over OTLP, the same
# protocol as the traces, at /api/v1/otlp/v1/metrics. That entrance comes switched off:
# --web.enable-otlp-receiver switches it on. The configuration the image brings is enough, because
# nobody is going to "scrape" the API: the API pushes. The metrics, in a volume, so they survive a
# restart; its web page and its API, only on your computer.
prometheus:
image: prom/prometheus:v3.15.0@sha256:efd719c99d83b060d9daefdcf00360461adf279f45ef5391f8d111892118753e
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.enable-otlp-receiver'
ports:
- '127.0.0.1:9090:9090'
volumes:
- prometheus-data:/prometheus
healthcheck:
test: ['CMD', 'wget', '-q', '--spider', 'http://127.0.0.1:9090/-/ready']
interval: 2s
timeout: 3s
retries: 15

GrafanaA program that draws charts and dashboards from data such as Prometheus’s, and can also send you an alert when a chart passes a limit.Go to definition doesn’t keep metrics: it asks Prometheus and draws. Everything it knows comes from files in the step. This one says where it reads from:

observability/grafana/provisioning/datasources/datasources.yaml
# Where Grafana reads from (Phase 10, lesson 5): Prometheus, for the metrics. The traces aren't
# here: Grafana's connector for Jaeger asks the old API (/api/services) and Jaeger 2.22 only serves
# the new one (/api/v3), so it wouldn't work. The traces are looked at in Jaeger's web page, at
# http://127.0.0.1:16686. The uid is the name the dashboards use to refer to the source.
apiVersion: 1
datasources:
- name: Prometheus
uid: prom
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true

Only Prometheus: Grafana’s connector for Jaeger asks for an API that Jaeger 2.22 no longer has, so traces are still looked at in Jaeger’s web page.

The dashboard, “The shop,” is another file, observability/grafana/dashboards/shop.json, with six graphs: the three RED ones, paid orders per minute, the queue and responses outside the contract. Being a file, it goes into Git, gets reviewed and comes out the same on any computer.

Grafana lets you in without a password and as an administrator (GF_AUTH_ANONYMOUS_ENABLED), and that’s why it’s only published on 127.0.0.1. On a server, never like that.

With the brakes below in place, when a load test with the dashboard open ended, docker stats gave: the API, 229 MiB; Prometheus, 43; Jaeger, 58, and Grafana, 294. Docker’s 2 GB virtual machine never had less than about 470 MB left.

Grafana weighs the most. As it comes, it installs 18 plugins, of which the shop uses one, and leaves 13 more processes running. While we were building this step, the system killed it twice for lack of memory: once during a load test, once with a panel editor open.

That’s why the step puts two brakes on it. It installs only the Prometheus plugin (GF_PLUGINS_PREINSTALL_SYNC) and disables the rest (GF_PLUGINS_DISABLE_PLUGINS): at rest, from about 450 to about 310 MiB. And GOMEMLIMIT: 250MiB asks its memory collector, Go’s, to clean up before going past that: at rest, about 210 MiB; with the web page in use during a load test, it reached 573 MiB without it, and 361 with it.

Jaeger had it happen first: it kept every trace of npm run load in memory, with no cap, until the system killed it. Now observability/jaeger.yaml sets max_traces: 5000 and throws away the oldest: under 394,000 requests, 58 MiB. Watching also costs, and that’s why in production traces are sampled.

The goal: see what the shop tells about itself; find out why three payments come out as 4.42 and why Prometheus and autocannon don’t give the same p99; and build the paid orders per minute panel by hand.

Outputs from October 24, 2026, with the shop on Node 26, on a MacBook with Docker in a 2 GB virtual machine. Your numbers will be different. The tables are from autocannon 8.0.0; 9.0.0 prints the same ones.

Put your project on step 45, as in the introduction:

Ventana de terminal
cd ~/backend-course/phase-3
curl -O https://backenddesdecero.com/practicas/shop-api/45-metrics.tar.gz
tar -xzf 45-metrics.tar.gz
cp -R 45-metrics/. shop-api/
cd shop-api
npm install
grep -q '^COMPOSE_FILE=' .env || printf '\nCOMPOSE_FILE=compose.yaml:compose.observability.yaml\n' >> .env
docker compose up -d --build --wait

The grep line checks whether your .env already has the COMPOSE_FILE from lesson 4’s “Try it”, and if not, adds it before starting. Two services show up: prometheus, with its web page at http://localhost:9090, and grafana, at http://localhost:3100.

The API can end up on port 3000 or 3001: Compose picks a free one from Phase 9’s range. Ask it which and keep it in a variable, API, which the commands below use:

0. The API’s port

Ventana de terminal
API=$(docker compose port api 3000)
echo $API

What you will see:

127.0.0.1:3000

It says which port of your computer the container’s 3000 is on. If you open another terminal, repeat the first line in it.

If Grafana stops answering and docker compose ps -a says Exited (137), the system killed it for lack of memory: docker compose up -d --wait starts it again.

Carmen, the practice customer, signs in, orders a mug and pays for it with the fake gateway, which sends the notice to SHOP_URL. -s removes npm’s lines, and the gateway writes two: what it sends (→) and what the shop answers (← 200):

Ventana de terminal
curl -s -o /dev/null -c carmen.txt --json '{"email":"carmen@example.com","password":"carmen-practice-2026"}' $API/v2/session
ORDER=$(curl -s -b carmen.txt --json '{"productId":2,"quantity":1}' $API/v2/orders | jq .id)
SHOP_URL=http://$API npm run -s gateway -- $ORDER

Wait about 10 seconds, what the API takes to send its metrics, and ask Prometheus which names it has:

1. The names

Ventana de terminal
curl -s localhost:9090/api/v1/label/__name__/values | jq -r '.data[]' | grep -E '^(http_|shop_)'

What you will see:

http_client_request_duration_seconds_bucket
http_client_request_duration_seconds_count
http_client_request_duration_seconds_sum
http_server_active_requests
http_server_request_duration_seconds_bucket
http_server_request_duration_seconds_count
http_server_request_duration_seconds_sum
shop_orders_paid_total
shop_queue_waiting

grep -E keeps the shop’s and the HTTP ones. The three http_server_… are the histogram; http_client_…, the one for the requests that leave the shop, and http_server_active_requests, the ones in progress. shop_responses_outside_contract_total is missing: a counter nobody has added anything to yet doesn’t exist. If shop_orders_paid_total is missing, wait another 5 seconds.

Three more orders, each one paid:

2. Three payments

Ventana de terminal
for i in 1 2 3; do
ORDER=$(curl -s -b carmen.txt --json '{"productId":2,"quantity":1}' $API/v2/orders | jq .id)
SHOP_URL=http://$API npm run -s gateway -- $ORDER
done

What you will see:

→ POST /v2/webhooks/payments {"id":"evt_800b58a3-9dd7-4bbb-9bcb-834be0d09237","type":"payment.completed","orderId":27}
← 200 {"received":"evt_800b58a3-9dd7-4bbb-9bcb-834be0d09237","repeated":false}
→ POST /v2/webhooks/payments {"id":"evt_7b109c92-c031-48ef-ae5a-a81ad42dccf1","type":"payment.completed","orderId":28}
← 200 {"received":"evt_7b109c92-c031-48ef-ae5a-a81ad42dccf1","repeated":false}
→ POST /v2/webhooks/payments {"id":"evt_9afe935d-ad78-431c-99fe-4c4a8a5ae3b5","type":"payment.completed","orderId":29}
← 200 {"received":"evt_9afe935d-ad78-431c-99fe-4c4a8a5ae3b5","repeated":false}

for repeats the last two commands from before three times. If the gateway answers Usage: npm run gateway…, the order wasn’t created and ORDER was left as null: check that echo $API gives a port and sign in again with the first command of the previous section.

Wait another 10 seconds and ask for the counter. -G with --data-urlencode puts the query in the URL; jq keeps only the labels and the value. You can paste the same query in Prometheus’s web page, at http://localhost:9090.

3. The counter and how much it went up

Ventana de terminal
curl -sG localhost:9090/api/v1/query --data-urlencode 'query=shop_orders_paid_total' | jq -c '.data.result[] | {metric, value: .value[1]}'
curl -sG localhost:9090/api/v1/query --data-urlencode 'query=increase(shop_orders_paid_total[5m])' | jq -c '.data.result[] | {metric, value: .value[1]}'

What you will see:

{"metric":{"__name__":"shop_orders_paid_total","job":"shop-api"},"value":"4"}
{"metric":{"job":"shop-api"},"value":"4.416616676664667"}

The counter says 4, and how much it went up in five minutes, 4.42. Two surprises:

  • The first payment doesn’t count. The series was born with it, worth 1, and Prometheus has no earlier value to subtract from.
  • Three payments give 4.42. The values arrive every 5 seconds, and the first and last ones Prometheus saw don’t fall on the edges of the window. So as not to fall short, it stretches the rise toward both edges, as if the counter had kept going at the same pace: all the way to the edge if it’s less than about one interval away, and half an interval if it’s farther. It extrapolates.

Ours: the values went from 1 to 4 over 15 seconds, and Prometheus stretched that 2.5 seconds back and about 4.6 forward. Three over 15 seconds, stretched to about 22: 4.42. rate and increase are good for trends; to count orders one by one, the database.

A load test, with the dashboard in front of you

Section titled “A load test, with the dashboard in front of you”

Open Grafana, http://localhost:3100, and in the menu on the left, Dashboards and The shop. It reloads every 5 seconds. With the dashboard in view, launch 75 seconds of load on the product list:

4. 75 seconds of load

Ventana de terminal
npm run load -- -c 10 -d 75 http://$API/v2/products

What you will see:

…
┌─────────┬──────┬──────┬───────┬──────┬────────┬─────────┬────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼──────┼──────┼───────┼──────┼────────┼─────────┼────────┤
│ Latency │ 1 ms │ 1 ms │ 4 ms │ 6 ms │ 1.4 ms │ 1.58 ms │ 190 ms │
└─────────┴──────┴──────┴───────┴──────┴────────┴─────────┴────────┘
┌───────────┬────────┬─────────┬─────────┬─────────┬──────────┬────────┬────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼────────┼─────────┼─────────┼─────────┼──────────┼────────┼────────┤
│ Req/Sec │ 2,999 │ 3,787 │ 5,543 │ 5,951 │ 5,251.83 │ 640.94 │ 2,998 │
├───────────┼────────┼─────────┼─────────┼─────────┼──────────┼────────┼────────┤
│ Bytes/Sec │ 2.8 MB │ 3.54 MB │ 5.18 MB │ 5.56 MB │ 4.9 MB │ 599 kB │ 2.8 MB │
└───────────┴────────┴─────────┴─────────┴─────────┴──────────┴────────┴────────┘
Req/Bytes counts sampled once per second.
# of samples: 75
394k requests in 75.01s, 368 MB read

We’ve removed the beginning. The load left our Mac through the published port, like yours: about 5,252 requests per second, with a 99% of 6 ms.

While it runs, on the dashboard:

  • Requests per second: the /v2/products line appears and climbs for a minute, up to about 5,300. When the load ends, it takes another minute to come down.
  • 5xx errors: “No data.” A healthy API leaves this panel empty.
  • p99 duration: /v2/products, at about 5 ms. The /health one goes up to about 25: Docker’s check queues up behind the load.
  • Paid orders and queue: still; the load only reads.

What Prometheus says, and why it doesn’t match

Section titled “What Prometheus says, and why it doesn’t match”

From another terminal, at 70 seconds of load, ask for each route’s requests per second:

5. Requests per second

Ventana de terminal
curl -sG localhost:9090/api/v1/query --data-urlencode 'query=sum by (http_route) (rate(http_server_request_duration_seconds_count{job="shop-api"}[1m]))' | jq -c '.data.result[] | {metric, value: .value[1]}'

What you will see:

{"metric":{"http_route":"/health"},"value":"0.09089256498818396"}
{"metric":{"http_route":"/v2/session"},"value":"0"}
{"metric":{"http_route":"/v2/orders"},"value":"0"}
{"metric":{"http_route":"/v2/webhooks/payments"},"value":"0"}
{"metric":{"http_route":"/v2/products"},"value":"5317.269587347755"}

5,317.3 for /v2/products, close to autocannon’s 5,252. /health gets about one every ten seconds: it’s Docker’s healthcheck. The other routes, at 0: they had requests before, and their series is still there.

The same query at 25 seconds gave us 2,044.6: the one-minute window still included 35 seconds without load. That’s why the dashboard’s line takes a minute to climb. With [15s] instead of [1m], at 70 seconds, it gave 5,308: a short window reacts sooner and jumps around more.

Now, the p99:

6. The p99, from the histogram

Ventana de terminal
curl -sG localhost:9090/api/v1/query --data-urlencode 'query=histogram_quantile(0.99, sum by (le, http_route) (rate(http_server_request_duration_seconds_bucket{job="shop-api"}[1m])))' | jq -c '.data.result[] | {metric, value: .value[1]}'

What you will see:

{"metric":{"http_route":"/health"},"value":"0.02475"}
{"metric":{"http_route":"/v2/session"},"value":"NaN"}
{"metric":{"http_route":"/v2/orders"},"value":"NaN"}
{"metric":{"http_route":"/v2/webhooks/payments"},"value":"NaN"}
{"metric":{"http_route":"/v2/products"},"value":"0.004954946425699238"}

In seconds: 4.95 ms for /v2/products. NaN (not a number) is a route with no requests in the last minute: there’s no percentile of nothing.

autocannon said 6 ms. With the same window, the histogram’s p50 gave 2.50 ms (autocannon, 1 ms) and the mean, _sum divided by _count, 0.68 ms (autocannon, 1.4). Neither one is lying:

  • They measure different things. The API measures from when it receives the request until it answers. autocannon, from your computer, adds the round trip through Docker’s published port.
  • The histogram only knows about buckets. Of the 5,317.3 requests per second, 5,312 took 5 ms or less: almost all of them in the first bucket. Inside it, histogram_quantile assumes they’re spread evenly. The p50 comes out in the middle of the bucket, 2.5; the p99, almost at the edge, 4.95. They’re estimates, as fine as the buckets.

In exchange, a histogram keeps 15 buckets and two totals, not every measurement, and it can be added up: with two copies of the API, you add their buckets and get the p99 of both together.

Now, the paid orders per minute one, from scratch:

  1. In Dashboards, press New and New dashboard.
  2. On the right, in Add, press the Panel box. In Title, type “Paid orders per minute.”
  3. Press Configure visualization. The source is already Prometheus. Switch Builder to Code, type sum(increase(shop_orders_paid_total[1m])) and press Run queries.
  4. At the top, change Last 6 hours to Last 15 minutes.
  5. Press Save, give it the title “My dashboards” and press Save again.

Run the three-payment for loop again and press Refresh. The line climbs to a bit over 3, stays there for a minute and goes back to 0. What it draws, asked of Prometheus right after paying:

7. The panel’s query

Ventana de terminal
curl -sG localhost:9090/api/v1/query --data-urlencode 'query=sum(increase(shop_orders_paid_total[1m]))' | jq -c '.data.result[] | {metric, value: .value[1]}'

What you will see:

{"metric":{},"value":"3.27189442687316"}

Three payments, 3.27: extrapolation again. sum joins the series of all the API’s copies, and that’s why metric comes out empty. A minute and a bit later, the same query gave us 0.

Your panel lives in Grafana’s database, inside its container. Recreate the container, as happens every time you change Grafana’s configuration:

8. Grafana, recreated

Ventana de terminal
docker compose up -d --force-recreate --wait grafana
curl -s localhost:3100/api/search | jq -c '.[] | {title, url}'

What you will see:

…
{"title":"The shop","url":"/d/shop/the-shop"}

We’ve removed Compose’s lines. “My dashboards” is gone, and “The shop” is still there, because it’s a file. That’s why real dashboards are saved as JSON, next to shop.json.

When you finish, delete carmen.txt: it carries Carmen’s session. Leave the shop running if you’re going on to lesson 6.

Your server’s .env doesn’t have OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: no metric is sent there, compose.production.yaml gains no service and the timer from Phase 8 deploys the step as always. If one day you set up Grafana on a server, give it a password and never leave it as an anonymous administrator.

  • The car’s dashboard, the one from the introduction: the odometer is a counter; the speedometer, a gauge.
  • A website’s Core Web Vitals: Google sorts visits into three buckets, good, needs improvement and poor, and judges by the 75th percentile. A histogram.
  • Drawing the counter as it is. A line that only goes up says nothing: rate or increase.
  • Using an id, a whole URL or an email as a label. One series per value, forever, and in the email’s case, personal data.
  • Averaging the p99s of several copies. It isn’t the p99 of anything: add up the buckets (sum by (le)) and get the percentile afterwards.
  • Believing a percentile’s decimals. It comes from the buckets; if almost everything falls in the first one, the number is an estimate.
  • Making dashboards with clicks only. They’re lost when Grafana is recreated and nobody reviews them: into a file.
  • A metric is a number with a time. Each combination of name and labels is a series: few labels, and with few values.
  • Counter for what only goes up (looked at with rate or increase), gauge for what goes up and down, histogram for durations and percentiles.
  • RED watches a service: requests, errors and duration, all three from the same histogram. USE watches resources, like the queue.
  • rate and increase look at a window backwards and extrapolate; histogram_quantile estimates inside a bucket. They’re trends, not exact counts.
  • The shop sends its metrics over OTLP to Prometheus, Grafana draws them from files, and the watching tools use memory too.
The shop_orders_paid_total panel goes up all afternoon and at night stays flat at 1,200, without going down. What does it tell you?

To know which customers buy the most, someone proposes adding the email as a label to shop.orders.paid. What do you tell them?

You have two copies of the API. One has a p99 of 10 ms and the other, of 300 ms. What’s the shop’s p99?

You launch a 30-second load test and, at 20 seconds, rate(…[1m]) says 1,800 per second, but autocannon measures 5,000. What’s going on?

With the shop running, the histogram gives a p50 of 2.5 ms and autocannon, of 1 ms. Which one is lying?

You freeze the queue’s Redis and the graph of jobs waiting stays flat at 3, without a gap. What do you know about the queue?

phase-10 · lesson 5/7