Trait cadence::Histogrammed

source ·
pub trait Histogrammed<T>{
    // Required method
    fn histogram_with_tags<'a>(
        &'a self,
        key: &'a str,
        value: T
    ) -> MetricBuilder<'_, '_, Histogram>;

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

Trait for recording histogram values.

Histogram values are positive values that can represent anything, whose statistical distribution is calculated by the server. The values can be timings, amount of some resource consumed, size of HTTP responses in some application, etc. Histograms can be thought of as a more general form of timers. Duration values are converted to nanoseconds before being emitted.

The following types are valid for histograms:

  • u64
  • f64
  • Duration

See the Statsd spec for more information.

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

Required Methods§

source

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

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

Provided Methods§

source

fn histogram(&self, key: &str, value: T) -> MetricResult<Histogram>

Record a single histogram value with the given key

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

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

    client.count("example.counter", 1).unwrap();
    client.gauge("example.gauge", 5).unwrap();
    client.gauge("example.gauge", 5.0).unwrap();
    client.time("example.timer", 32).unwrap();
    client.time("example.timer", Duration::from_millis(32)).unwrap();
    client.histogram("example.histogram", 22).unwrap();
    client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
    client.histogram("example.histogram", 22.0).unwrap();
    client.distribution("example.distribution", 33).unwrap();
    client.distribution("example.distribution", 33.0).unwrap();
    client.meter("example.meter", 8).unwrap();
    client.set("example.set", 44).unwrap();
}
examples/wrapped.rs (line 63)
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
fn main() {
    let real_sink = NopMetricSink;
    let reference1 = CloneableSink::new(real_sink);
    let reference2 = reference1.clone();
    let client = StatsdClient::from_sink("prefix", reference1);

    let _ = reference2.flush();

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

    let _ = reference2.flush();
}
examples/production-sink.rs (line 31)
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 buffered = BufferedUdpMetricSink::from(("localhost", DEFAULT_PORT), sock).unwrap();
    let queued = QueuingMetricSink::from(buffered);
    let client = StatsdClient::from_sink("example.prefix", queued);

    client.count("example.counter", 1).unwrap();
    client.gauge("example.gauge", 5).unwrap();
    client.gauge("example.gauge", 5.0).unwrap();
    client.time("example.timer", 32).unwrap();
    client.time("example.timer", Duration::from_millis(32)).unwrap();
    client.histogram("example.histogram", 22).unwrap();
    client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
    client.histogram("example.histogram", 22.0).unwrap();
    client.distribution("example.distribution", 33).unwrap();
    client.distribution("example.distribution", 33.0).unwrap();
    client.meter("example.meter", 8).unwrap();
    client.set("example.set", 44).unwrap();
}
examples/unix-socket.rs (line 40)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 client = StatsdClient::from_sink("example.prefix", sink);

            client.count("example.counter", 1).unwrap();
            client.gauge("example.gauge", 5).unwrap();
            client.gauge("example.gauge", 5.0).unwrap();
            client.time("example.timer", 32).unwrap();
            client.time("example.timer", Duration::from_millis(32)).unwrap();
            client.histogram("example.histogram", 22).unwrap();
            client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
            client.histogram("example.histogram", 22.0).unwrap();
            client.distribution("example.distribution", 33).unwrap();
            client.distribution("example.distribution", 33.0).unwrap();
            client.meter("example.meter", 8).unwrap();
            client.set("example.set", 44).unwrap();
        },
    );
}
examples/spy-sink.rs (line 32)
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
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 client = StatsdClient::from_sink("example.prefix", sink);

        client.count("example.counter", 1).unwrap();
        client.gauge("example.gauge", 5).unwrap();
        client.gauge("example.gauge", 5.0).unwrap();
        client.time("example.timer", 32).unwrap();
        client.time("example.timer", Duration::from_millis(32)).unwrap();
        client.histogram("example.histogram", 22).unwrap();
        client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
        client.histogram("example.histogram", 22.0).unwrap();
        client.distribution("example.distribution", 33).unwrap();
        client.distribution("example.distribution", 33.0).unwrap();
        client.meter("example.meter", 8).unwrap();
        client.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§