pub trait Histogrammed<T>where
T: ToHistogramValue,{
// Required method
fn histogram_with_tags<'a>(
&'a self,
key: &'a str,
value: T,
) -> MetricBuilder<'a, 'a, 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:
u64f64Duration
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§
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§
Sourcefn histogram(&self, key: &str, value: T) -> MetricResult<Histogram>
fn histogram(&self, key: &str, value: T) -> MetricResult<Histogram>
Record a single histogram value with the given key
Examples found in repository?
18fn main() {
19 let sink = NopMetricSink;
20 let client = StatsdClient::from_sink("example.prefix", sink);
21
22 client.count("example.counter", 1).unwrap();
23 client.gauge("example.gauge", 5).unwrap();
24 client.gauge("example.gauge", 5.0).unwrap();
25 client.time("example.timer", 32).unwrap();
26 client.time("example.timer", Duration::from_millis(32)).unwrap();
27 client.histogram("example.histogram", 22).unwrap();
28 client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
29 client.histogram("example.histogram", 22.0).unwrap();
30 client.distribution("example.distribution", 33).unwrap();
31 client.distribution("example.distribution", 33.0).unwrap();
32 client.meter("example.meter", 8).unwrap();
33 client.set("example.set", 44).unwrap();
34}More examples
19fn main() {
20 let sock = UdpSocket::bind("0.0.0.0:0").unwrap();
21 let sink = UdpMetricSink::from(("localhost", DEFAULT_PORT), sock).unwrap();
22 let client = StatsdClient::from_sink("example.prefix", sink);
23
24 client.count("example.counter", 1).unwrap();
25 client.gauge("example.gauge", 5).unwrap();
26 client.gauge("example.gauge", 5.0).unwrap();
27 client.time("example.timer", 32).unwrap();
28 client.time("example.timer", Duration::from_millis(32)).unwrap();
29 client.histogram("example.histogram", 22).unwrap();
30 client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
31 client.histogram("example.histogram", 22.0).unwrap();
32 client.distribution("example.distribution", 33).unwrap();
33 client.distribution("example.distribution", 33.0).unwrap();
34 client.meter("example.meter", 8).unwrap();
35 client.set("example.set", 44).unwrap();
36}50fn main() {
51 let real_sink = NopMetricSink;
52 let reference1 = CloneableSink::new(real_sink);
53 let reference2 = reference1.clone();
54 let client = StatsdClient::from_sink("prefix", reference1);
55
56 let _ = reference2.flush();
57
58 client.count("example.counter", 1).unwrap();
59 client.gauge("example.gauge", 5).unwrap();
60 client.gauge("example.gauge", 5.0).unwrap();
61 client.time("example.timer", 32).unwrap();
62 client.time("example.timer", Duration::from_millis(32)).unwrap();
63 client.histogram("example.histogram", 22).unwrap();
64 client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
65 client.histogram("example.histogram", 22.0).unwrap();
66 client.distribution("example.distribution", 33).unwrap();
67 client.distribution("example.distribution", 33.0).unwrap();
68 client.meter("example.meter", 8).unwrap();
69 client.set("example.set", 44).unwrap();
70
71 let _ = reference2.flush();
72}20fn main() {
21 let sock = UdpSocket::bind("0.0.0.0:0").unwrap();
22 let buffered = BufferedUdpMetricSink::from(("localhost", DEFAULT_PORT), sock).unwrap();
23 let queued = QueuingMetricSink::from(buffered);
24 let client = StatsdClient::from_sink("example.prefix", queued);
25
26 client.count("example.counter", 1).unwrap();
27 client.gauge("example.gauge", 5).unwrap();
28 client.gauge("example.gauge", 5.0).unwrap();
29 client.time("example.timer", 32).unwrap();
30 client.time("example.timer", Duration::from_millis(32)).unwrap();
31 client.histogram("example.histogram", 22).unwrap();
32 client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
33 client.histogram("example.histogram", 22.0).unwrap();
34 client.distribution("example.distribution", 33).unwrap();
35 client.distribution("example.distribution", 33.0).unwrap();
36 client.meter("example.meter", 8).unwrap();
37 client.set("example.set", 44).unwrap();
38}26fn main() {
27 let harness = UnixServerHarness::new("unix-socket-example");
28 harness.run(
29 |s: String| println!("Got {} bytes from socket: {}", s.len(), s),
30 |path| {
31 let socket = UnixDatagram::unbound().unwrap();
32 let sink = UnixMetricSink::from(path, socket);
33 let client = StatsdClient::from_sink("example.prefix", sink);
34
35 client.count("example.counter", 1).unwrap();
36 client.gauge("example.gauge", 5).unwrap();
37 client.gauge("example.gauge", 5.0).unwrap();
38 client.time("example.timer", 32).unwrap();
39 client.time("example.timer", Duration::from_millis(32)).unwrap();
40 client.histogram("example.histogram", 22).unwrap();
41 client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
42 client.histogram("example.histogram", 22.0).unwrap();
43 client.distribution("example.distribution", 33).unwrap();
44 client.distribution("example.distribution", 33.0).unwrap();
45 client.meter("example.meter", 8).unwrap();
46 client.set("example.set", 44).unwrap();
47 },
48 );
49}19fn main() {
20 // Ensure that the sink is dropped, forcing a flush of all buffered metrics.
21 let rx = {
22 // Use a buffer size larger than any metrics here so we can demonstrate that
23 // each metric ends up with a newline (\n) after it.
24 let (rx, sink) = BufferedSpyMetricSink::with_capacity(None, Some(64));
25 let client = StatsdClient::from_sink("example.prefix", sink);
26
27 client.count("example.counter", 1).unwrap();
28 client.gauge("example.gauge", 5).unwrap();
29 client.gauge("example.gauge", 5.0).unwrap();
30 client.time("example.timer", 32).unwrap();
31 client.time("example.timer", Duration::from_millis(32)).unwrap();
32 client.histogram("example.histogram", 22).unwrap();
33 client.histogram("example.histogram", Duration::from_nanos(22)).unwrap();
34 client.histogram("example.histogram", 22.0).unwrap();
35 client.distribution("example.distribution", 33).unwrap();
36 client.distribution("example.distribution", 33.0).unwrap();
37 client.meter("example.meter", 8).unwrap();
38 client.set("example.set", 44).unwrap();
39
40 rx
41 };
42
43 let mut buffer = Vec::new();
44 while let Ok(v) = rx.try_recv() {
45 buffer.extend(v);
46 }
47
48 println!("Contents of wrapped buffer:\n{}", String::from_utf8(buffer).unwrap());
49}