Counter and gauge are two basic metric types. A counter is a cumulative value that only increases or resets to zero, such as the total number of requests or errors. A gauge is a snapshot of a current value that can go up and down, such as memory usage or queue length. The type determines how a metric is queried.
What are counters and gauges?
A metric is a numeric measurement recorded over time, and every metric has a type that describes how its values should be interpreted. The two most fundamental types are the counter and the gauge. Both appear in Prometheus and in OpenTelemetry, and getting the choice right is a prerequisite for meaningful dashboards and alerts.
- A counter counts things that happen: requests served, bytes sent, errors thrown. Its value only increases, except when the process restarts and the counter resets to zero.
- A gauge measures a state at a moment: memory in use, active connections, items in a queue, CPU temperature. Its value can rise and fall arbitrarily.
Counters in detail
The raw value of a counter is rarely interesting on its own. That a service has handled 18,452,903 requests since its last restart says little. What matters is how fast the counter grows. In PromQL you therefore almost always wrap counters in rate() or increase():
# requests per second, averaged over 5 minutes
rate(http_requests_total[5m])
# errors in the last hour
increase(http_requests_total{status=~"5.."}[1h])
These functions detect counter resets: if a value is lower than the previous one, Prometheus assumes a restart and continues the calculation correctly. By convention, Prometheus counter names end in _total, for example http_requests_total. Counters are the basis for throughput and error rate, two of the golden signals.
Gauges in detail
A gauge is read as it is: the current value is the information. Typical queries look at the value directly or summarize it over a time window:
# current memory usage per pod
container_memory_working_set_bytes{namespace="shop"}
# maximum queue length in the last 10 minutes
max_over_time(queue_messages_ready[10m])
Applying rate() to a gauge produces meaningless results, because a falling value would be misinterpreted as a counter reset. For the rate of change of a gauge, PromQL offers deriv(), and predict_linear() extrapolates a gauge, for example to warn before a disk is full. Gauges are typical for saturation signals.
Keep in mind that a gauge is only sampled at scrape or export intervals. A queue that fills up and drains again within 30 seconds may never show up in a gauge scraped every minute. If short peaks matter, record the maximum in the application or count the underlying occurrences with a counter.
Counters and gauges in OpenTelemetry
OpenTelemetry defines instruments that map onto these types, with synchronous variants called in your code and asynchronous (observable) variants read through a callback at collection time:
| OpenTelemetry instrument | Behavior | Example |
|---|---|---|
| Counter / ObservableCounter | Monotonic, only increases | Requests, bytes sent |
| UpDownCounter / ObservableUpDownCounter | Additive, can increase and decrease | Active requests, queue size |
| Gauge / ObservableGauge | Non-additive current value | CPU temperature, memory utilization |
| Histogram | Distribution of measurements | Request duration |
The UpDownCounter sits between both types: it tracks a sum that can go up and down, such as the number of items in a queue, where adding values across instances makes sense. A gauge, by contrast, records values like temperature where a sum across instances would be meaningless. OpenTelemetry sums can be exported with cumulative or delta temporality; Prometheus works with cumulative values.
Which type to choose
- Do you count occurrences? Use a counter and query its rate.
- Do you measure a current level that can fall? Use a gauge or an UpDownCounter.
- Do you need distributions such as p95 latency? Use a histogram, not a gauge with an average.
- Never store a pre-computed rate as a gauge if you can expose the counter; the backend can compute rates over any window from the counter.
For both types, the same rule applies to labels: every unique combination of label values creates a separate time series, so avoid user IDs or request IDs as labels.
A practical example shows how the types work together. A message consumer exposes a counter messages_processed_total, a counter messages_failed_total, a gauge for the current lag behind the newest message and a histogram for processing time. The rate of the first counter is the throughput, the ratio of both counters is the error rate, the gauge shows whether the consumer keeps up, and the histogram reveals slow outliers.
How Obseria helps
Obseria accepts counters, gauges, UpDownCounters and histograms via OTLP and Prometheus remote write, and you query them with PromQL, OQL or SQL. Metrics monitoring recognizes the metric type and suggests the matching aggregation, such as a rate for counters.