Understanding Prometheus Metric Types: Counter, Gauge, Histogram, and Summary
This article explains the four core Prometheus metric types—Counter, Gauge, Histogram, and Summary—detailing their characteristics, appropriate use cases, PromQL functions, and how they differ, while providing language-specific client library references and visual examples.
Prometheus client libraries provide four core metric types. While client libraries expose distinct APIs, the Prometheus server treats them as untyped time series; future versions aim to differentiate them.
Counter
A Counter represents a monotonically increasing value that only goes up (unless the monitoring system resets). It is suitable for tracking request counts, completed tasks, error occurrences, etc.
Counters help understand event rate changes; PromQL functions can analyze them, e.g., HTTP request volume.
Do not use Counters for non‑monotonic metrics such as the current number of processes (use Gauge instead).
Go
Java
Python
Ruby
Gauge
A Gauge represents a metric that can arbitrarily increase or decrease, suitable for values like temperature, memory usage, or the current number of concurrent requests.
PromQL's delta() function can compute changes over time, for example: delta(cpu_temp_celsius{host="zeus"}[2h]) The predict_linear() function can forecast future values based on linear regression:
predict_linear(node_filesystem_free{job="node"}[2h], 4 * 3600) < 0Go
Java
Python
Ruby
Histogram
Histograms sample data over a time range (e.g., request latency) and place observations into configurable buckets. They provide three metrics per series: _bucket{le="<upper bound>"}: count of samples less than or equal to the upper bound. _sum: total sum of all sample values. _count: total number of samples (identical to _bucket{le="+Inf"}).
Use histogram_quantile() to compute quantiles, and the histogram can also calculate Apdex scores.
Go
Java
Python
Ruby
Summary
Summaries also sample data over time but store quantiles directly (computed by the client), rather than using buckets.
They expose three metrics per series: {quantile="<φ>"}: the value of the specified quantile. _sum: total sum of all sample values. _count: total number of samples.
Go
Java
Python
Ruby
Comparison
Both Histogram and Summary expose _sum and _count metrics.
Histograms require _bucket to compute quantiles, whereas Summaries store quantile values directly.
For detailed usage, refer to the Prometheus documentation on histograms and summaries.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
