Counter

Struct Counter 

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

A counter of absolute observed values (non-negative amounts). Used to count things that cannot be undone:

  • Bytes sent
  • Records written
  • Apples eaten

For relative (possibly negative) values, the Level counter type can be used. If aggregated, minimum and maximum scores will track the collected values, not their sum.

Implementations§

Source§

impl Counter

Source

pub fn count(&self, count: usize)

Record a value count.

Examples found in repository?
examples/macro_proxy.rs (line 39)
35fn main() {
36    dipstick::Proxy::default_target(Stream::write_to_stdout().metrics());
37
38    loop {
39        ROOT_COUNTER.count(123);
40        ANOTHER_COUNTER.count(456);
41        ROOT_TIMER.interval_us(2000000);
42        ROOT_GAUGE.value(34534);
43        std::thread::sleep(Duration::from_millis(40));
44    }
45}
More examples
Hide additional examples
examples/graphite.rs (line 13)
6fn main() {
7    let metrics = Graphite::send_to("localhost:2003")
8        .expect("Connected")
9        .named("my_app")
10        .metrics();
11
12    loop {
13        metrics.counter("counter_a").count(123);
14        metrics.timer("timer_a").interval_us(2000000);
15        std::thread::sleep(Duration::from_millis(40));
16    }
17}
examples/text_format_label.rs (line 40)
32fn main() {
33    let counter = Stream::write_to_stderr()
34        .formatting(MyFormat)
35        .metrics()
36        .counter("counter_a");
37    AppLabel::set("abc", "xyz");
38    loop {
39        // report some metric values from our "application" loop
40        counter.count(11);
41        sleep(Duration::from_millis(500));
42    }
43}
examples/cache.rs (line 16)
8fn main() {
9    let metrics = Stream::write_to(io::stdout())
10        .cached(5)
11        .metrics()
12        .named("cache");
13
14    loop {
15        // report some ad-hoc metric values from our "application" loop
16        metrics.counter("blorf").count(1134);
17        metrics.marker("burg").mark();
18
19        sleep(Duration::from_millis(500));
20    }
21}
examples/statsd_sampling.rs (line 17)
6fn main() {
7    let metrics = Statsd::send_to("localhost:8125")
8        .expect("Connected")
9        .sampled(Sampling::Random(0.2))
10        .named("my_app")
11        .metrics();
12
13    let counter = metrics.counter("counter_a");
14
15    loop {
16        for i in 1..11 {
17            counter.count(i);
18        }
19        std::thread::sleep(Duration::from_millis(3000));
20    }
21}
examples/statsd_nosampling.rs (line 17)
6fn main() {
7    let metrics = Statsd::send_to("localhost:8125")
8        .expect("Connected")
9        //            .with_sampling(Sampling::Random(0.2))
10        .named("my_app")
11        .metrics();
12
13    let counter = metrics.counter("counter_a");
14
15    loop {
16        for i in 1..11 as usize {
17            counter.count(i);
18        }
19        std::thread::sleep(Duration::from_millis(3000));
20    }
21}

Methods from Deref<Target = InputMetric>§

Source

pub fn write(&self, value: MetricValue, labels: Labels)

Collect a new value for this metric.

Examples found in repository?
examples/raw_log.rs (line 16)
10pub fn raw_write() {
11    // setup dual metric channels
12    let metrics_log = dipstick::Log::to_log().metrics();
13
14    // define and send metrics using raw channel API
15    let counter = metrics_log.new_metric("count_a".into(), dipstick::InputKind::Counter);
16    counter.write(1, labels![]);
17}
Source

pub fn metric_id(&self) -> &MetricId

Returns the unique identifier of this metric.

Trait Implementations§

Source§

impl Clone for Counter

Source§

fn clone(&self) -> Counter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Counter

Source§

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

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

impl From<InputMetric> for Counter

Source§

fn from(metric: InputMetric) -> Counter

Converts to this type from the input type.
Source§

impl Deref for Counter

Source§

type Target = InputMetric

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.