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§

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

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![]);
}

Returns the unique identifier of this metric.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Converts to this type from the input type.

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.