concept

Counter, Gauge and Histogram

The three fundamental metric types, distinguished by what they represent over time and by which aggregations are valid.

Choosing the wrong type produces numbers that look meaningful and are not.

Counter — monotonically increasing; only ever goes up (or resets to zero on restart). Requests served, errors, bytes processed. You query its rate, not its value. Restart handling is why the distinction from a gauge matters: monitoring systems know a counter reset is not a negative rate.

Gauge — a value that can rise and fall: current memory, queue depth, active connections, temperature. Aggregating gauges across instances requires care — summing queue depth is meaningful, summing percentages is not.

Histogram — a distribution recorded as bucket counts, from which quantiles are computed. Essential for latency, because averages hide the behaviour that matters: an average of 100 ms is compatible with 95% of requests at 50 ms and 5% at 1 s, and it is the 5% that generates complaints.

The histogram detail that catches people: quantiles cannot be averaged across instances. Averaging three instances' p99 gives a number with no meaning. Aggregate the underlying buckets, then compute the quantile — which is why bucket boundaries must be chosen deliberately and consistently.