Metrics: counters, gauges, histograms

Play this lesson

How many gardens, right now?

Priya, who runs observability, wants a graph of live gardens, every 15 seconds, for the last month. Counting garden.start log lines would mean reading billions of them.

A metric is a measurement of a service taken while it runs. Instead of one line per event, the server keeps a running number and reports it every few seconds, so the cost hardly changes whether 10 or 10,000 gardens are playing.

Four metric types

These are the names in Prometheus, an open-source monitoring system. OpenTelemetry has the same ideas, plus an UpDownCounter: a count that can also go down, like players in a lobby.

Pick the type

Which type fits "co-op gardens running right now"?

  1. Gauge
  2. Counter
  3. Histogram
Show the answer

Gauge

The number of live gardens goes up and down all day. A counter can only go up, and a histogram sorts measurements like durations into buckets.

Counters become rates

garden_saves_total only grows: 1,204,511 saves since the server started. That number alone says little. Dashboards turn it into a rate: how fast it grew over the last 5 minutes, for example 420 saves a second.

Prometheus's rule: do not use a counter for a value that can decrease. Players in a lobby join and leave, so a counter would be wrong for them.

Quick check

Players currently in a lobby should be a counter, because we are counting them.

Show the answer

False

The number goes down when players leave, and a counter may only go up. It is a gauge, or an UpDownCounter in OpenTelemetry.

Inside a histogram

A histogram of join times sends three kinds of numbers:

Sum divided by count gives the average. The buckets give much more: the shape of the whole spread, slow tail included.

Names and labels

Prometheus's naming rules: one unit per metric, in base units (seconds and bytes, not milliseconds and megabytes), with the unit at the end of the name, and _total on counters.

Labels split a metric: region="eu", build="1.4.2". Every combination of label values is a separate time series to store. So Prometheus warns: no labels with many possible values, like user IDs or email addresses.

Bug hunt

metrics.txt
joins_total{region="eu"}join_secs_bucket{le="0.5"}saves_total{player_id="p9"}

Priya's metrics bill jumps after a release. Which line is the problem?

  1. Line 1
  2. Line 2
  3. Line 3
Show the answer

Line 3

A player_id label makes one time series per player, a set that keeps growing. Prometheus warns against labels like user IDs. Player IDs belong in logs and traces.

The average is hiding something

Shard Garden's average save time looks great. Players still say saves sometimes hang. Both can be true.

Bolt says: Next: percentiles, p50, p95 and p99, and why averages lie.

Fact-checked 11 October 2026