Struct dipstick::Stream

source ·
pub struct Stream<W: Write + Send + Sync + 'static> { /* private fields */ }
Expand description

Buffered metrics text Input.

Implementations§

Write metric values to provided Write target.

Examples found in repository?
examples/cache.rs (line 9)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
    let metrics = Stream::write_to(io::stdout())
        .cached(5)
        .metrics()
        .named("cache");

    loop {
        // report some ad-hoc metric values from our "application" loop
        metrics.counter("blorf").count(1134);
        metrics.marker("burg").mark();

        sleep(Duration::from_millis(500));
    }
}
More examples
Hide additional examples
examples/basics.rs (line 11)
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);
}
👎Deprecated since 0.8.0: Use write_to_file()

Write metric values to a file.

Write metric values to a file.

👎Deprecated since 0.8.0: Use write_to_new_file()

Write metrics to a new file.

Creates a new file to dump data into. If clobber is set to true, it allows overwriting existing file, if false, the attempt will result in an error.

Write metrics to a new file.

Creates a new file to dump data into. If clobber is set to true, it allows overwriting existing file, if false, the attempt will result in an error.

👎Deprecated since 0.8.0: Use write_to_stderr()

Write metric values to stderr.

Write metric values to stderr.

Examples found in repository?
examples/text_format_label.rs (line 33)
32
33
34
35
36
37
38
39
40
41
42
43
fn main() {
    let counter = Stream::write_to_stderr()
        .formatting(MyFormat)
        .metrics()
        .counter("counter_a");
    AppLabel::set("abc", "xyz");
    loop {
        // report some metric values from our "application" loop
        counter.count(11);
        sleep(Duration::from_millis(500));
    }
}
More examples
Hide additional examples
examples/multi_input.rs (line 15)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    // will output metrics to graphite and to stdout
    let different_type_metrics = MultiInput::new()
        .add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
        .add_target(Stream::write_to_stdout())
        .metrics();

    // will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix.
    let same_type_metrics = MultiInput::new()
        .add_target(Stream::write_to_stderr().named("yeah"))
        .add_target(Stream::write_to_stderr().named("ouch"))
        .named("both")
        .metrics();

    loop {
        different_type_metrics.counter("counter_a").count(123);
        same_type_metrics.timer("timer_a").interval_us(2000000);
        std::thread::sleep(Duration::from_millis(400));
    }
}
examples/custom_publish.rs (line 43)
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);
    }
}
👎Deprecated since 0.8.0: Use write_to_stdout()

Write metric values to stdout.

Write metric values to stdout.

Examples found in repository?
examples/macro_proxy.rs (line 36)
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/buffered_flush_on_drop.rs (line 9)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let input = Stream::write_to_stdout().buffered(Buffering::Unlimited);

    loop {
        println!("\n------- open scope");

        let metrics = input.metrics();

        metrics.marker("marker_a").mark();

        sleep(Duration::from_millis(1000));

        println!("------- close scope: ");
    }
}
examples/bucket_cleanup.rs (line 10)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let bucket = AtomicBucket::new();
    AtomicBucket::default_drain(Stream::write_to_stdout());

    let persistent_marker = bucket.marker("persistent");

    let mut i = 0;

    loop {
        i += 1;
        let transient_marker = bucket.marker(&format!("marker_{}", i));

        transient_marker.mark();
        persistent_marker.mark();

        bucket.flush().unwrap();

        sleep(Duration::from_secs(1));
    }
}
examples/async_queue.rs (line 9)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let async_metrics = Stream::write_to_stdout().queued(100).metrics();
    let counter = async_metrics.counter("counter_a");
    for _ in 0..4 {
        let counter = counter.clone();
        thread::spawn(move || {
            loop {
                // report some metric values from our "application" loop
                counter.count(11);
                sleep(Duration::from_millis(50));
            }
        });
    }
    sleep(Duration::from_secs(5000));
}
examples/bench_bucket.rs (line 28)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    let bucket = AtomicBucket::new();
    let event = bucket.marker("a");
    let args = &mut args();
    args.next();
    let tc: u8 = u8::from_str(&args.next().unwrap()).unwrap();
    for _ in 0..tc {
        let event = event.clone();
        thread::spawn(move || {
            loop {
                // report some metric values from our "application" loop
                event.mark();
            }
        });
    }
    sleep(Duration::from_secs(5));
    bucket.stats(stats_all);
    bucket
        .flush_to(&Stream::write_to_stdout().metrics())
        .unwrap();
}
examples/bench_bucket_proxy.rs (line 31)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() {
    let event = Proxy::default().marker("a");

    let bucket = AtomicBucket::new();

    Proxy::default().target(bucket.clone());

    let args = &mut args();
    args.next();
    let tc: u8 = u8::from_str(&args.next().unwrap()).unwrap();
    for _ in 0..tc {
        let event = event.clone();
        thread::spawn(move || {
            loop {
                // report some metric values from our "application" loop
                event.mark();
            }
        });
    }
    sleep(Duration::from_secs(5));
    bucket
        .flush_to(&Stream::write_to_stdout().metrics())
        .unwrap();
}

Trait Implementations§

Return a clone with the specified buffering set.
Return the current buffering strategy.
Returns false if the current buffering strategy is Buffering::Unbuffered. Returns true otherwise.
Wrap an input with a metric definition cache. This can provide performance benefits for metrics that are dynamically defined at runtime on each access. Caching is useless if all metrics are statically declared or instantiated programmatically in advance and referenced by a long living variable.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Specify formatting of output.
The type of Scope returned byt this input.
Open a new scope from this input.
👎Deprecated since 0.7.2: Use metrics()
Open a new scope from this input.
👎Deprecated since 0.8.0: Use metrics()
Open a new scope from this input.
Wrap this output with an asynchronous dispatch queue of specified length.
Return attributes of component.
Return attributes of component for mutation.
Clone the component and mutate its attributes at once.

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.