Struct dipstick::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)
35
36
37
38
39
40
41
42
43
44
45
fn main() {
    dipstick::Proxy::default_target(Stream::write_to_stdout().metrics());

    loop {
        ROOT_COUNTER.count(123);
        ANOTHER_COUNTER.count(456);
        ROOT_TIMER.interval_us(2000000);
        ROOT_GAUGE.value(34534);
        std::thread::sleep(Duration::from_millis(40));
    }
}
More examples
Hide additional examples
examples/graphite.rs (line 13)
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let metrics = Graphite::send_to("localhost:2003")
        .expect("Connected")
        .named("my_app")
        .metrics();

    loop {
        metrics.counter("counter_a").count(123);
        metrics.timer("timer_a").interval_us(2000000);
        std::thread::sleep(Duration::from_millis(40));
    }
}
examples/text_format_label.rs (line 40)
32
33
34
35
36
37
38
39
40
41
42
43
fn main() {
    let counter = Stream::write_to_stderr()
        .formatting(MyFormat)
        .metrics()
        .counter("counter_a");
    AppLabel::set("abc", "xyz");
    loop {
        // report some metric values from our "application" loop
        counter.count(11);
        sleep(Duration::from_millis(500));
    }
}
examples/cache.rs (line 16)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
    let metrics = Stream::write_to(io::stdout())
        .cached(5)
        .metrics()
        .named("cache");

    loop {
        // report some ad-hoc metric values from our "application" loop
        metrics.counter("blorf").count(1134);
        metrics.marker("burg").mark();

        sleep(Duration::from_millis(500));
    }
}
examples/statsd_sampling.rs (line 17)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
    let metrics = Statsd::send_to("localhost:8125")
        .expect("Connected")
        .sampled(Sampling::Random(0.2))
        .named("my_app")
        .metrics();

    let counter = metrics.counter("counter_a");

    loop {
        for i in 1..11 {
            counter.count(i);
        }
        std::thread::sleep(Duration::from_millis(3000));
    }
}
examples/statsd_nosampling.rs (line 17)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
    let metrics = Statsd::send_to("localhost:8125")
        .expect("Connected")
        //            .with_sampling(Sampling::Random(0.2))
        .named("my_app")
        .metrics();

    let counter = metrics.counter("counter_a");

    loop {
        for i in 1..11 as usize {
            counter.count(i);
        }
        std::thread::sleep(Duration::from_millis(3000));
    }
}

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)
10
11
12
13
14
15
16
17
pub fn raw_write() {
    // setup dual metric channels
    let metrics_log = dipstick::Log::to_log().metrics();

    // define and send metrics using raw channel API
    let counter = metrics_log.new_metric("count_a".into(), dipstick::InputKind::Counter);
    counter.write(1, labels![]);
}
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 copy 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

§

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

§

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>,

§

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>,

§

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.