Use it when instrumenting code or writing queries.
Counters, Gauges and Histograms
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.
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.
observation → typed metric → correct query function
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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.
Always use rate()/increase() on counters, never raw values. Histograms can be aggregated across instances; summaries cannot. Choose buckets around your SLO thresholds.
curl -s localhost:9090/api/v1/metadata?metric=<name>— first check for this topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool 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
| Type | Use | Query with |
|---|---|---|
| Counter | Requests, errors, bytes | rate(), increase() |
| Gauge | Temperature, queue length, memory in use | Value directly, avg_over_time() |
| Histogram | Latency, sizes (buckets) | histogram_quantile() |
| Summary | Client-side quantiles | Cannot 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
| Histogram | Summary | |
|---|---|---|
| Computed | Buckets counted in the app, quantiles at query time | Quantiles computed in the app |
| Aggregate across instances | Yes — sum the buckets, then histogram_quantile | No — averaging p99s is mathematically wrong |
| Choose quantiles later | Yes | No |
| Accuracy | Depends on bucket boundaries | Exact per instance (within its window) |
| Cost | One series per bucket | One 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.
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
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.