Gauge is a synchronous instrument that records independent, non-additive values. Gauges are ideal for measurements where only the current value matters, such as CPU usage, memory consumption, or temperature.
When to Use Gauge
Use a Gauge when:- Only the current/latest value is meaningful
- Values are independent measurements (not cumulative)
- You’re measuring instantaneous state
- Historical values aren’t aggregated
- CPU usage percentage
- Memory consumption
- Temperature readings
- Cache size
- Queue depth at a point in time
- Thread pool size
Gauges record point-in-time values. The last value recorded is what gets exported. Unlike histograms, gauges don’t calculate distributions or percentiles.
API Reference
record method sets the current value of the gauge.
Creating a Gauge
Gauges supportu64, i64, and f64 data types:
Recording Measurements
Use therecord method to set the current value:
Complete Example
Example from Source
From themetrics-basic example:
Gauge Types
Choose the appropriate numeric type:u64 Gauge
For non-negative integers:i64 Gauge
For integers that can be negative:f64 Gauge
For floating-point values (most common):Gauge vs. ObservableGauge
Choose based on when you record measurements:Attributes and Cardinality
Gauges support attributes to track multiple related measurements:Cloning Gauges
Gauges can be cloned to share across your application:Gauge vs. Histogram
Understand when to use each:Gauge vs. UpDownCounter
Different use cases:Common Use Cases
System Metrics
Application Metrics
Environmental Sensors
Best Practices
- Use for current state: Gauges are for “what is the value now”
- Choose the right type: Use
f64for percentages and decimals,u64for counts,i64when negative values are possible - Specify units: Use standard units like
"%","By","Cel","{entries}" - Keep cardinality low: Limit unique attribute combinations
- Clone, don’t duplicate: Share gauges by cloning, not recreating
- Consider ObservableGauge: Use callbacks when reading from external sources
Next Steps
Counter
Record monotonically increasing values
Histogram
Record value distributions
Observable Instruments
Use ObservableGauge with callbacks
Views
Customize gauge aggregation