pub struct Counter(/* private fields */);
Expand description
Counter
is a cumulative metric that represents a single numerical value that only ever goes up.
Cloned counters share the same value.
§Examples
use prometrics::metrics::CounterBuilder;
let mut counter = CounterBuilder::new("foo_total").namespace("example").finish().unwrap();
assert_eq!(counter.metric_name().to_string(), "example_foo_total");
assert_eq!(counter.value(), 0.0);
counter.increment();
assert_eq!(counter.value(), 1.0);
Implementations§
Source§impl Counter
impl Counter
Sourcepub fn new(name: &str) -> Result<Self>
pub fn new(name: &str) -> Result<Self>
Makes a new Counter
instance.
Note that it is recommended to create this via CounterBuilder
.
Sourcepub fn metric_name(&self) -> &MetricName
pub fn metric_name(&self) -> &MetricName
Returns the name of this counter.
Sourcepub fn labels_mut(&mut self) -> LabelsMut<'_>
pub fn labels_mut(&mut self) -> LabelsMut<'_>
Returns the mutable labels of this counter.
Sourcepub fn timestamp_mut(&self) -> TimestampMut<'_>
pub fn timestamp_mut(&self) -> TimestampMut<'_>
Returns the mutable timestamp of this counter.
Sourcepub fn time<F, T>(&self, f: F) -> Twhere
F: FnOnce() -> T,
pub fn time<F, T>(&self, f: F) -> Twhere
F: FnOnce() -> T,
Measures the exeuction time of f
and adds its duration to the counter in seconds.
Sourcepub fn collector(&self) -> CounterCollector
pub fn collector(&self) -> CounterCollector
Returns a collector for this counter.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Counter
impl RefUnwindSafe for Counter
impl Send for Counter
impl Sync for Counter
impl Unpin for Counter
impl UnwindSafe for Counter
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)