Trait dipstick::Sampled

source ·
pub trait Sampled: WithAttributes {
    fn sampled(&self, sampling: Sampling) -> Self { ... }
    fn get_sampling(&self) -> Sampling { ... }
}
Expand description

Apply statistical sampling to collected metrics data.

Provided Methods§

Perform random sampling of values according to the specified rate.

Examples found in repository?
examples/statsd_sampling.rs (line 9)
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));
    }
}
More examples
Hide additional examples
examples/per_metric_sampling.rs (line 16)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    let statsd = Statsd::send_to("localhost:8125")
        .expect("Connected")
        .named("my_app");
    // Sampling::Full is the default
    // .sampled(Sampling::Full);

    let unsampled_marker = statsd.metrics().marker("marker_a");

    let low_freq_marker = statsd
        .sampled(Sampling::Random(0.1))
        .metrics()
        .marker("low_freq_marker");

    let hi_freq_marker = statsd
        .sampled(Sampling::Random(0.001))
        .metrics()
        .marker("hi_freq_marker");

    loop {
        unsampled_marker.mark();

        for _i in 0..10 {
            low_freq_marker.mark();
        }
        for _i in 0..1000 {
            hi_freq_marker.mark();
        }
        std::thread::sleep(Duration::from_millis(3000));
    }
}

Get the sampling strategy for this component, if any.

Implementors§