pub struct Counter<N = u64, A = AtomicU64> { /* private fields */ }
Expand description

Open Metrics Counter to measure discrete events.

Single monotonically increasing value metric.

Counter is generic over the actual data type tracking the Counter state as well as the data type used to interact with the Counter. Out of convenience the generic type parameters are set to use an AtomicU64 as a storage and u64 on the interface by default.

Examples

Using AtomicU64 as storage and u64 on the interface

let counter: Counter = Counter::default();
counter.inc();
let _value: u64 = counter.get();

Using AtomicU64 as storage and f64 on the interface

let counter = Counter::<f64, AtomicU64>::default();
counter.inc();
let _value: f64 = counter.get();

Implementations§

Increase the Counter by 1, returning the previous value.

Increase the Counter by v, returning the previous value.

Get the current value of the Counter.

Exposes the inner atomic type of the Counter.

This should only be used for advanced use-cases which are not directly supported by the library.

The caller of this function has to uphold the property of an Open Metrics counter namely that the value is monotonically increasing, i.e. either stays the same or increases.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.