[go: up one dir, main page]

Gauged

Trait Gauged 

Source
pub trait Gauged<T>
where T: ToGaugeValue,
{ // Required method fn gauge_with_tags<'a>( &'a self, key: &'a str, value: T, ) -> MetricBuilder<'a, 'a, Gauge>; // Provided method fn gauge(&self, key: &str, value: T) -> MetricResult<Gauge> { ... } }
Expand description

Trait for recording gauge values.

Gauge values are an instantaneous measurement of a value determined by the client. They do not change unless changed by the client. Examples include things like load average or how many connections are active.

The following types are valid for gauges:

  • u64
  • f64

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 gauge_with_tags<'a>( &'a self, key: &'a str, value: T, ) -> MetricBuilder<'a, 'a, Gauge>

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

Provided Methods§

Source

fn gauge(&self, key: &str, value: T) -> MetricResult<Gauge>

Record a gauge value with the given key

Examples found in repository?
examples/custom-value-type.rs (line 39)
35fn main() {
36    let sink = NopMetricSink;
37    let client = StatsdClient::from_sink("example.prefix", sink);
38
39    client.gauge("user.happiness", UserHappiness::VeryHappy).unwrap();
40    client.gauge("user.happiness", UserHappiness::KindaHappy).unwrap();
41    client.gauge("user.happiness", UserHappiness::Sad).unwrap();
42}
More examples
Hide additional examples
examples/nop-sink.rs (line 23)
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 25)
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 59)
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 27)
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 36)
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§

Source§

impl<T> Gauged<T> for StatsdClient
where T: ToGaugeValue,