Skip to main content
A 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
Common examples:
  • 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

The record method sets the current value of the gauge.

Creating a Gauge

Gauges support u64, i64, and f64 data types:

Recording Measurements

Use the record method to set the current value:
Each call to record with the same attribute set overwrites the previous value. Only the last recorded value is exported.

Complete Example

Example from Source

From the metrics-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:
See Observable Instruments for more on asynchronous gauges.

Attributes and Cardinality

Gauges support attributes to track multiple related measurements:
Each unique attribute combination creates a separate gauge value. Keep cardinality reasonable to avoid memory issues.

Cloning Gauges

Gauges can be cloned to share across your application:
Clone gauges when sharing across modules. Avoid creating multiple gauges with the same name.

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

  1. Use for current state: Gauges are for “what is the value now”
  2. Choose the right type: Use f64 for percentages and decimals, u64 for counts, i64 when negative values are possible
  3. Specify units: Use standard units like "%", "By", "Cel", "{entries}"
  4. Keep cardinality low: Limit unique attribute combinations
  5. Clone, don’t duplicate: Share gauges by cloning, not recreating
  6. 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