Struct dipstick::Gauge

source ·
pub struct Gauge { /* private fields */ }
Expand description

A gauge that sends values to the metrics backend

Implementations§

Record a value point for this gauge.

Examples found in repository?
examples/macro_proxy.rs (line 42)
35
36
37
38
39
40
41
42
43
44
45
fn main() {
    dipstick::Proxy::default_target(Stream::write_to_stdout().metrics());

    loop {
        ROOT_COUNTER.count(123);
        ANOTHER_COUNTER.count(456);
        ROOT_TIMER.interval_us(2000000);
        ROOT_GAUGE.value(34534);
        std::thread::sleep(Duration::from_millis(40));
    }
}
More examples
Hide additional examples
examples/bucket2stdout.rs (line 29)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn main() {
    let metrics = AtomicBucket::new().named("test");

    metrics.drain(Stream::write_to_stdout());

    metrics.flush_every(Duration::from_secs(3));

    let counter = metrics.counter("counter_a");
    let timer = metrics.timer("timer_a");
    let gauge = metrics.gauge("gauge_a");
    let marker = metrics.marker("marker_a");

    loop {
        // add counts forever, non-stop
        counter.count(11);
        counter.count(12);
        counter.count(13);

        timer.interval_us(11_000_000);
        timer.interval_us(12_000_000);
        timer.interval_us(13_000_000);

        gauge.value(11);
        gauge.value(12);
        gauge.value(13);

        marker.mark();
    }
}
examples/bucket_summary.rs (line 28)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() {
    let app_metrics = AtomicBucket::new();
    app_metrics.drain(Stream::write_to_stdout());

    app_metrics.flush_every(Duration::from_secs(3));

    let counter = app_metrics.counter("counter_a");
    let timer = app_metrics.timer("timer_a");
    let gauge = app_metrics.gauge("gauge_a");
    let marker = app_metrics.marker("marker_a");

    loop {
        // add counts forever, non-stop
        counter.count(11);
        counter.count(12);
        counter.count(13);

        timer.interval_us(11_000_000);
        timer.interval_us(12_000_000);
        timer.interval_us(13_000_000);

        gauge.value(11);
        gauge.value(12);
        gauge.value(13);

        marker.mark();
    }
}
examples/bucket2graphite.rs (line 37)
7
8
9
10
11
12
13
14
15
16
17
18
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
fn main() {
    // adding a name to the stats
    let bucket = AtomicBucket::new().named("test");

    // adding two names to Graphite output
    // metrics will be prefixed with "machine1.application.test"
    bucket.drain(
        Graphite::send_to("localhost:2003")
            .expect("Socket")
            .named("machine1")
            .add_name("application"),
    );

    bucket.flush_every(Duration::from_secs(3));

    let counter = bucket.counter("counter_a");
    let timer = bucket.timer("timer_a");
    let gauge = bucket.gauge("gauge_a");
    let marker = bucket.marker("marker_a");

    loop {
        // add counts forever, non-stop
        counter.count(11);
        counter.count(12);
        counter.count(13);

        timer.interval_us(11_000_000);
        timer.interval_us(12_000_000);
        timer.interval_us(13_000_000);

        gauge.value(11);
        gauge.value(12);
        gauge.value(13);

        marker.mark();
    }
}
examples/basics.rs (line 31)
9
10
11
12
13
14
15
16
17
18
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
50
fn main() {
    // for this demo, print metric values to the console
    let app_metrics = Stream::write_to(io::stdout()).metrics();

    // metrics can be predefined by type and name
    let counter = app_metrics.counter("counter_a");
    let level = app_metrics.level("level_a");
    let timer = app_metrics.timer("timer_b");

    // metrics can also be declared and used ad-hoc (use output.cache() if this happens often)
    app_metrics.counter("just_once").count(4);

    // metric names can be prepended with a common prefix
    let prefixed_metrics = app_metrics.named("subsystem");
    let event = prefixed_metrics.marker("event_c");
    let gauge = prefixed_metrics.gauge("gauge_d");

    // each kind of metric has a different method name to prevent errors
    counter.count(11);
    level.adjust(-4);
    level.adjust(5);

    gauge.value(22);
    gauge.value(-24);

    event.mark();

    // time can be measured multiple equivalent ways:
    // in microseconds (used internally)
    timer.interval_us(35573);

    // using the time! macro
    time!(timer, sleep(Duration::from_millis(5)));

    // using a closure
    timer.time(|| sleep(Duration::from_millis(5)));

    // using a "time handle"
    let start_time = timer.start();
    sleep(Duration::from_millis(5));
    timer.stop(start_time);
}
examples/custom_publish.rs (line 57)
7
8
9
10
11
12
13
14
15
16
17
18
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
50
51
52
53
54
55
56
57
58
59
fn main() {
    fn custom_statistics(
        kind: InputKind,
        mut name: MetricName,
        score: ScoreType,
    ) -> Option<(InputKind, MetricName, MetricValue)> {
        match (kind, score) {
            // do not export gauge scores
            (InputKind::Gauge, _) => None,

            // prepend and append to metric name
            (_, ScoreType::Count(count)) => {
                if let Some(last) = name.pop_back() {
                    Some((
                        InputKind::Counter,
                        name.append("customized_add_prefix")
                            .append(format!("{}_and_a_suffix", last)),
                        count,
                    ))
                } else {
                    None
                }
            }

            // scaling the score value and appending unit to name
            (kind, ScoreType::Sum(sum)) => Some((kind, name.append("per_thousand"), sum / 1000)),

            // using the unmodified metric name
            (kind, ScoreType::Mean(avg)) => Some((kind, name, avg.round() as MetricValue)),

            // do not export min and max
            _ => None,
        }
    }

    // send application metrics to aggregator
    AtomicBucket::default_drain(Stream::write_to_stderr());
    AtomicBucket::default_stats(custom_statistics);

    let app_metrics = AtomicBucket::new();

    // schedule aggregated metrics to be printed every 3 seconds
    app_metrics.flush_every(Duration::from_secs(3));

    let counter = app_metrics.counter("counter_a");
    let timer = app_metrics.timer("timer_b");
    let gauge = app_metrics.gauge("gauge_c");
    loop {
        counter.count(11);
        timer.interval_us(654654);
        gauge.value(3534);
    }
}

Methods from Deref<Target = InputMetric>§

Collect a new value for this metric.

Examples found in repository?
examples/raw_log.rs (line 16)
10
11
12
13
14
15
16
17
pub fn raw_write() {
    // setup dual metric channels
    let metrics_log = dipstick::Log::to_log().metrics();

    // define and send metrics using raw channel API
    let counter = metrics_log.new_metric("count_a".into(), dipstick::InputKind::Counter);
    counter.write(1, labels![]);
}

Returns the unique identifier of this metric.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.