Trait cadence::Distributed

source ·
pub trait Distributed<T>where
    T: ToDistributionValue,{
    // Required method
    fn distribution_with_tags<'a>(
        &'a self,
        key: &'a str,
        value: T
    ) -> MetricBuilder<'_, '_, Distribution>;

    // Provided method
    fn distribution(&self, key: &str, value: T) -> MetricResult<Distribution> { ... }
}
Expand description

Trait for recording distribution values.

Similar to histograms, but applies globally. A distribution can be used to instrument logical objects, like services, independently from the underlying hosts.

The following types are valid for distributions:

  • u64
  • f64

See the Datadog docs for more information.

Note that tags and distributions are a Datadog extension to Statsd and may not be supported by your server.

Required Methods§

source

fn distribution_with_tags<'a>( &'a self, key: &'a str, value: T ) -> MetricBuilder<'_, '_, Distribution>

Record a single distribution value with the given key and return a MetricBuilder that can be used to add tags to the metric.

Provided Methods§

source

fn distribution(&self, key: &str, value: T) -> MetricResult<Distribution>

Record a single distribution value with the given key

Examples found in repository?
examples/nop-sink.rs (line 32)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    let sink = NopMetricSink;
    let metrics = StatsdClient::from_sink("example.prefix", sink);

    metrics.count("example.counter", 1).unwrap();
    metrics.gauge("example.gauge", 5).unwrap();
    metrics.gauge("example.gauge", 5.0).unwrap();
    metrics.time("example.timer", 32).unwrap();
    metrics.time("example.timer", Duration::from_millis(32)).unwrap();
    metrics.histogram("example.histogram", 22).unwrap();
    metrics
        .histogram("example.histogram", Duration::from_nanos(22))
        .unwrap();
    metrics.histogram("example.histogram", 22.0).unwrap();
    metrics.distribution("example.distribution", 33).unwrap();
    metrics.distribution("example.distribution", 33.0).unwrap();
    metrics.meter("example.meter", 8).unwrap();
    metrics.set("example.set", 44).unwrap();
}
More examples
Hide additional examples
examples/simple-sink.rs (line 34)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fn main() {
    let sock = UdpSocket::bind("0.0.0.0:0").unwrap();
    let sink = UdpMetricSink::from(("localhost", DEFAULT_PORT), sock).unwrap();
    let metrics = StatsdClient::from_sink("example.prefix", sink);

    metrics.count("example.counter", 1).unwrap();
    metrics.gauge("example.gauge", 5).unwrap();
    metrics.gauge("example.gauge", 5.0).unwrap();
    metrics.time("example.timer", 32).unwrap();
    metrics.time("example.timer", Duration::from_millis(32)).unwrap();
    metrics.histogram("example.histogram", 22).unwrap();
    metrics
        .histogram("example.histogram", Duration::from_nanos(22))
        .unwrap();
    metrics.histogram("example.histogram", 22.0).unwrap();
    metrics.distribution("example.distribution", 33).unwrap();
    metrics.distribution("example.distribution", 33.0).unwrap();
    metrics.meter("example.meter", 8).unwrap();
    metrics.set("example.set", 44).unwrap();
}
examples/production-sink.rs (line 36)
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() {
    let sock = UdpSocket::bind("0.0.0.0:0").unwrap();
    let buffered = BufferedUdpMetricSink::from(("localhost", DEFAULT_PORT), sock).unwrap();
    let queued = QueuingMetricSink::from(buffered);
    let metrics = StatsdClient::from_sink("example.prefix", queued);

    metrics.count("example.counter", 1).unwrap();
    metrics.gauge("example.gauge", 5).unwrap();
    metrics.gauge("example.gauge", 5.0).unwrap();
    metrics.time("example.timer", 32).unwrap();
    metrics.time("example.timer", Duration::from_millis(32)).unwrap();
    metrics.histogram("example.histogram", 22).unwrap();
    metrics
        .histogram("example.histogram", Duration::from_nanos(22))
        .unwrap();
    metrics.histogram("example.histogram", 22.0).unwrap();
    metrics.distribution("example.distribution", 33).unwrap();
    metrics.distribution("example.distribution", 33.0).unwrap();
    metrics.meter("example.meter", 8).unwrap();
    metrics.set("example.set", 44).unwrap();
}
examples/unix-socket.rs (line 45)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let harness = UnixServerHarness::new("unix-socket-example");
    harness.run(
        |s: String| println!("Got {} bytes from socket: {}", s.len(), s),
        |path| {
            let socket = UnixDatagram::unbound().unwrap();
            let sink = UnixMetricSink::from(path, socket);
            let metrics = StatsdClient::from_sink("example.prefix", sink);

            metrics.count("example.counter", 1).unwrap();
            metrics.gauge("example.gauge", 5).unwrap();
            metrics.gauge("example.gauge", 5.0).unwrap();
            metrics.time("example.timer", 32).unwrap();
            metrics.time("example.timer", Duration::from_millis(32)).unwrap();
            metrics.histogram("example.histogram", 22).unwrap();
            metrics
                .histogram("example.histogram", Duration::from_nanos(22))
                .unwrap();
            metrics.histogram("example.histogram", 22.0).unwrap();
            metrics.distribution("example.distribution", 33).unwrap();
            metrics.distribution("example.distribution", 33.0).unwrap();
            metrics.meter("example.meter", 8).unwrap();
            metrics.set("example.set", 44).unwrap();
        },
    );
}
examples/spy-sink.rs (line 37)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    // Ensure that the sink is dropped, forcing a flush of all buffered metrics.
    let rx = {
        // Use a buffer size larger than any metrics here so we can demonstrate that
        // each metric ends up with a newline (\n) after it.
        let (rx, sink) = BufferedSpyMetricSink::with_capacity(None, Some(64));
        let metrics = StatsdClient::from_sink("example.prefix", sink);

        metrics.count("example.counter", 1).unwrap();
        metrics.gauge("example.gauge", 5).unwrap();
        metrics.gauge("example.gauge", 5.0).unwrap();
        metrics.time("example.timer", 32).unwrap();
        metrics.time("example.timer", Duration::from_millis(32)).unwrap();
        metrics.histogram("example.histogram", 22).unwrap();
        metrics
            .histogram("example.histogram", Duration::from_nanos(22))
            .unwrap();
        metrics.histogram("example.histogram", 22.0).unwrap();
        metrics.distribution("example.distribution", 33).unwrap();
        metrics.distribution("example.distribution", 33.0).unwrap();
        metrics.meter("example.meter", 8).unwrap();
        metrics.set("example.set", 44).unwrap();

        rx
    };

    let mut buffer = Vec::new();
    while let Ok(v) = rx.try_recv() {
        buffer.extend(v);
    }

    println!("Contents of wrapped buffer:\n{}", String::from_utf8(buffer).unwrap());
}

Implementors§