pub struct Gauge { /* private fields */ }Expand description
A cache-padded atomic gauge for point-in-time measurements.
Gauges represent a current value that is periodically sampled and set, such as memory usage, queue depth, or progress percentage.
§Why Only set() and get()?
This type intentionally omits add()/inc()/dec() methods. If you need
to increment or decrement a value from multiple threads (e.g., tracking
active connections), use Counter instead - it’s thread-sharded for
contention-free concurrent increments.
Providing increment methods here would create a footgun: the API would look
convenient for counting, but the single-atomic implementation would cause
cache-line contention under concurrent writes. By limiting the API to
set()/get(), we make the intended usage pattern clear: periodic
point-in-time snapshots from a single writer.
§Why Not Thread-Sharded?
Thread-sharding works for Counter because addition is commutative — you
can sum the shards to get the total. This includes subtraction (adding
negative values): the shard sums still produce the correct aggregate.
set() is not commutative; there’s no meaningful way to aggregate “last
value written” across shards.
The cache padding prevents false sharing if this gauge is stored adjacent to frequently-accessed data.
Implementations§
Trait Implementations§
Source§impl ClickHouseExport for Gauge
impl ClickHouseExport for Gauge
fn export_clickhouse( &self, batch: &mut ClickHouseMetricBatch, name: &str, description: &str, time_unix_nano: u64, )
Source§impl DogStatsDExport for Gauge
impl DogStatsDExport for Gauge
Source§impl OtlpExport for Gauge
impl OtlpExport for Gauge
Auto Trait Implementations§
impl !Freeze for Gauge
impl RefUnwindSafe for Gauge
impl Send for Gauge
impl Sync for Gauge
impl Unpin for Gauge
impl UnsafeUnpin for Gauge
impl UnwindSafe for Gauge
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request