Struct dipstick::Level

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

A counter of fluctuating resources accepting positive and negative values. Can be used as a stateful Gauge or as a Counter of possibly decreasing amounts.

  • Size of messages in a queue
  • Strawberries on a conveyor belt If aggregated, minimum and maximum scores will track the sum of values, not the collected values themselves.

Implementations§

Record a positive or negative value count

Examples found in repository?
examples/basics.rs (line 28)
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);
}

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.