Skip to main content

Gauge

Struct Gauge 

Source
pub struct Gauge { /* private fields */ }
Expand description

A signed gauge whose value may go up, down, or be set to an absolute number. Backed by AtomicI64 because Prometheus gauges are unrestricted-sign floats; we clamp to i64 here because every data-plane gauge in the workspace (open sessions, queue depth, spool bytes) is a non-negative count that fits comfortably in 63 bits, and the signed representation lets sub_saturating bottom out at 0 rather than wrap.

Implementations§

Source§

impl Gauge

Source

pub fn set(&self, value: u64)

Set the gauge to an absolute value. Truncates to i64::MAX on overflow — no data-plane count in the workspace is even close to that ceiling, and silently overflowing to a negative value would produce misleading dashboards.

Source

pub fn inc(&self)

Increment by 1. Saturates at i64::MAX.

Source

pub fn dec(&self)

Decrement by 1. Saturates at 0 — a gauge going negative is almost always a lifecycle bookkeeping bug (dec called twice for one inc), and rendering -1 open_sessions would confuse every dashboard downstream.

Source

pub fn add(&self, n: u64)

Increment by n. Saturates at i64::MAX.

Source

pub fn sub(&self, n: u64)

Decrement by n. Saturates at 0.

Source

pub fn get(&self) -> u64

Current value as an unsigned integer — the saturating math above guarantees non-negativity so the cast never truncates a real observation.

Trait Implementations§

Source§

impl Debug for Gauge

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Gauge

Source§

fn default() -> Gauge

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more