1
2
3
4
5
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
//! A sample application sending ad-hoc marker values both to statsd _and_ to stdout.

use dipstick::*;
use std::time::Duration;

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));
    }
}