Struct prometheus_client::metrics::counter::Counter
source · 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§
source§impl<N, A: Atomic<N>> Counter<N, A>
impl<N, A: Atomic<N>> Counter<N, A>
sourcepub fn inner(&self) -> &A
pub fn inner(&self) -> &A
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§
source§impl<N, A> EncodeMetric for Counter<N, A>where
N: EncodeCounterValue,
A: Atomic<N>,
impl<N, A> EncodeMetric for Counter<N, A>where
N: EncodeCounterValue,
A: Atomic<N>,
source§fn encode(&self, encoder: MetricEncoder<'_>) -> Result<(), Error>
fn encode(&self, encoder: MetricEncoder<'_>) -> Result<(), Error>
Encode the given instance in the OpenMetrics text encoding.
source§fn metric_type(&self) -> MetricType
fn metric_type(&self) -> MetricType
The OpenMetrics metric type of the instance.
source§impl<N, A> TypedMetric for Counter<N, A>
impl<N, A> TypedMetric for Counter<N, A>
source§const TYPE: MetricType = MetricType::Counter
const TYPE: MetricType = MetricType::Counter
The OpenMetrics metric type.
Auto Trait Implementations§
impl<N, A> Freeze for Counter<N, A>
impl<N, A> RefUnwindSafe for Counter<N, A>where
N: RefUnwindSafe,
A: RefUnwindSafe,
impl<N, A> Send for Counter<N, A>
impl<N, A> Sync for Counter<N, A>
impl<N, A> Unpin for Counter<N, A>where
N: Unpin,
impl<N, A> UnwindSafe for Counter<N, A>where
A: RefUnwindSafe,
N: UnwindSafe,
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)