Pcornel
Browse topics
Options
Recent
Favorites
Observability · Technical reference

Counters, Gauges and Histograms

Direct answer

Metric types: counters only increase (reset on restart), gauges go up and down, histograms count observations in buckets (for quantiles), summaries compute quantiles client-side.

When to use this

Use it when instrumenting code or writing queries.

First 30 seconds

1. Type from metadata: curl -s localhost:9090/api/v1/metadata?metric=<name>.

2. Counter → rate(x[5m]).

3. Gauge → use as is, or avg/max.

4. Histogram → histogram_quantile.

5. Buckets cover SLO thresholds.

Operational verification

observation → typed metric → correct query function

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
OpenTelemetry / Prometheus / Grafana / common metrics-log-trace pipelines
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformOpenTelemetry / Prometheus / Grafana / common metrics-log-trace pipelines
Scope / prerequisiteUse it when instrumenting code or writing queries.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Confirm units in metric names (_seconds, _bytes, _total). Check that bucket boundaries cover the expected latency range.

Step 2 Common failures Narrow the fault

Using a gauge for request counts loses data between scrapes. Averaging percentiles across instances gives wrong numbers. Buckets that stop below real latency make every slow request look the same.

Key points

Always use rate()/increase() on counters, never raw values. Histograms can be aggregated across instances; summaries cannot. Choose buckets around your SLO thresholds.

Key checks
  • curl -s localhost:9090/api/v1/metadata?metric=<name> — first check for this topic
  • curl -s localhost:9090/-/ready — Prometheus ready
  • curl -s 'localhost:9090/api/v1/query?query=up' — scrape targets up/down
  • promtool check config prometheus.yml — config valid
ReferenceWhat it is1 section · depth on demand

How it works

Counters reset to zero on restart; rate() handles resets. Histogram buckets are cumulative (le = less than or equal). Summaries compute quantiles on the client but cannot be aggregated across instances.

ReferenceImportant terms & boundaries3 sections · depth on demand

Metric types

TypeUseQuery with
CounterRequests, errors, bytesrate(), increase()
GaugeTemperature, queue length, memory in useValue directly, avg_over_time()
HistogramLatency, sizes (buckets)histogram_quantile()
SummaryClient-side quantilesCannot be aggregated across instances

Prefer histograms over summaries for latency so percentiles can be aggregated. Native histograms in Prometheus reduce bucket configuration.

In depth

Counter

Only goes up (resets to 0 on restart). The raw value is rarely useful; query the rate:

rate(http_requests_total[5m])          # per-second average over 5 min, handles resets
increase(http_requests_total[1h])      # total increase in the last hour (extrapolated)

Gauge

Goes up and down: memory in use, queue length, temperature. Query the value directly, or with avg_over_time, max_over_time, deriv (slope). Never rate() a gauge.

Histogram vs summary

HistogramSummary
ComputedBuckets counted in the app, quantiles at query timeQuantiles computed in the app
Aggregate across instancesYes — sum the buckets, then histogram_quantileNo — averaging p99s is mathematically wrong
Choose quantiles laterYesNo
AccuracyDepends on bucket boundariesExact per instance (within its window)
CostOne series per bucketOne series per quantile

Bucket boundaries matter

histogram_quantile interpolates linearly inside a bucket. With buckets at 0.1 s and 1 s, a p99 of "0.55 s" only means "somewhere between 0.1 and 1 s". Put boundaries around the latencies you care about, especially at your SLO threshold (for example 0.25, 0.3, 0.5 s for a 300 ms target).

histogram_quantile(0.95, sum by (le, route) (rate(http_server_request_duration_seconds_bucket[5m])))

Native histograms (exponential buckets chosen automatically, one series per histogram) remove most of the bucket-choice problem where Prometheus and the client library support them.

Naming

Base units and suffixes: _seconds, _bytes, _total for counters, _ratio for 0–1 values, _info for metadata gauges with value 1.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • Using gauges for things that only increase.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
counters, gauges and histogramsprometheus metric typeshistogram_quantile
Confirmation

Confirm action

Continue?