[go: up one dir, main page]

Counted

Trait Counted 

Source
pub trait Counted<T>
where T: ToCounterValue,
{ // Required method fn count_with_tags<'a>( &'a self, key: &'a str, count: T, ) -> MetricBuilder<'a, 'a, Counter>; // Provided method fn count(&self, key: &str, count: T) -> MetricResult<Counter> { ... } }
Expand description

Trait for incrementing and decrementing counters.

Counters are simple values incremented or decremented by a client. The rates at which these events occur or average values will be determined by the server receiving them. Examples of counter uses include number of logins to a system or requests received.

The following types are valid for counters:

  • i64

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§

Source

fn count_with_tags<'a>( &'a self, key: &'a str, count: T, ) -> MetricBuilder<'a, 'a, Counter>

Increment or decrement the counter by the given amount and return a MetricBuilder that can be used to add tags to the metric.

Provided Methods§

Source

fn count(&self, key: &str, count: T) -> MetricResult<Counter>

Increment or decrement the counter by the given amount

Examples found in repository?
examples/arc-wrapped-client.rs (line 40)
36    fn handle(&self) -> Result<(), String> {
37        let metrics_ref = self.metrics.clone();
38
39        let t = thread::spawn(move || {
40            let _ = metrics_ref.count("request.handled", 1);
41            println!("Hello from a threaded handler!");
42        });
43
44        t.join().unwrap();
45        Ok(())
46    }
More examples
Hide additional examples
examples/nop-sink.rs (line 22)
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}
examples/simple-sink.rs (line 24)
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 58)
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 26)
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 35)
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}

Implementors§