Pregunta de Monitoring and Logging #019e3a4f
What is the core metric type in Prometheus used to represent a single numerical value that can go up and down?
Summary
Counter
Histogram
Gauge
Explicación Oficial / Explicaciones de la Comunidad
In Prometheus, the core metric type used to represent a single numerical value that can go up and down is the Gauge. Gauges are used for values that can arbitrarily increase or decrease, such as temperature, memory usage, or number of concurrent requests. They are snapshot values that can be set to any number and can change over time in either direction.
How it Works
A Gauge is a metric that represents a single numerical value that can be arbitrarily increased or decreased. It is typically used for measurements like current memory usage, CPU temperature, or number of active connections. Gauges can be set to a specific value using the Set() method, or incremented/decremented using Inc(), Dec(), Add(), or Sub() methods. In PromQL, gauge metrics can be used with functions like avg(), sum(), min(), max(), and delta() to compute changes over time.
Why the Correct Value is Right
The Gauge is the correct metric type because it is explicitly designed to represent a single numerical value that can go up and down. It is the only Prometheus metric type that supports both increases and decreases, making it suitable for values that are not monotonically increasing.
Why the Incorrect Values are Wrong
- Counter: A Counter is a cumulative metric that only increases (or resets to zero on restart). It is used for values that only go up, such as total requests or errors. Counters cannot decrease, so they are not suitable for values that can go down.
- Histogram: A Histogram samples observations (like request durations or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values. Histograms are used for distributions, not for a single value that goes up and down.
- Summary: Similar to a Histogram, a Summary samples observations and calculates configurable quantiles over a sliding time window. It also provides a total count and sum of observations. Summaries are used for tracking distributions and are not designed for a single fluctuating value.