pub trait Timed<T>where
T: ToTimerValue,{
// Required method
fn time_with_tags<'a>(
&'a self,
key: &'a str,
time: T,
) -> MetricBuilder<'a, 'a, Timer>;
// Provided method
fn time(&self, key: &str, time: T) -> MetricResult<Timer> { ... }
}Expand description
Trait for recording timings in milliseconds.
Timings are a positive number of milliseconds between a start and end
time. Examples include time taken to render a web page or time taken
for a database call to return. Duration values are converted to
milliseconds before being recorded.
The following types are valid for timers:
u64Duration
See the Statsd spec for more information.
Note that tags are a Datadog extension to Statsd and may not be supported by your server.
Required Methods§
Record a timing in milliseconds with the given key and return a
MetricBuilder that can be used to add tags to the metric.
Provided Methods§
Sourcefn time(&self, key: &str, time: T) -> MetricResult<Timer>
fn time(&self, key: &str, time: T) -> MetricResult<Timer>
Record a timing in milliseconds with the given key
Examples found in repository?
examples/nop-sink.rs (line 25)
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
examples/simple-sink.rs (line 27)
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}examples/wrapped.rs (line 61)
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}examples/production-sink.rs (line 29)
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}examples/unix-socket.rs (line 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}examples/spy-sink.rs (line 30)
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}