#metrics #logging

witchcraft-metrics

A general-purpose metrics library

3 unstable releases

0.2.0 Dec 1, 2020
0.1.1 Jan 21, 2020
0.1.0 Nov 21, 2019

#72 in Profiling

Download history 26/week @ 2021-08-10 16/week @ 2021-08-17 20/week @ 2021-08-24 16/week @ 2021-08-31 27/week @ 2021-09-07 46/week @ 2021-09-14 50/week @ 2021-09-21 31/week @ 2021-09-28 59/week @ 2021-10-05 35/week @ 2021-10-12 17/week @ 2021-10-19 32/week @ 2021-10-26 31/week @ 2021-11-02 33/week @ 2021-11-09 75/week @ 2021-11-16 52/week @ 2021-11-23

204 downloads per month
Used in 2 crates

Apache-2.0

46KB
980 lines

witchcraft-rust-logging

CircleCI

Logging infrastructure for Witchcraft services.

witchcraft-log

Documentation

A structured logging facade. It differs from the traditional log by adding a concept of "safety" to log parameters and allowing a conjure-error Error to be attached to log records.

witchcraft-metrics

Documentation

A general-purpose metrics library. The design of the crate is based fairly closely off of the Dropwizard Metrics library from the Java ecosystem.

License

This repository is made available under the Apache 2.0 License.


lib.rs:

A general-purpose metrics library.

The design of the crate is based fairly closely off of the Dropwizard Metrics library from the Java ecosystem.

Examples

use witchcraft_metrics::{MetricRegistry, MetricId, Metric};
use std::time::Duration;

// A `MetricRegistry` stores metrics.
let registry = MetricRegistry::new();

// Metrics are identified by an ID, which consists of a name and set of "tags"
let yaks_shaved = registry.counter(MetricId::new("shavings").with_tag("animal", "yak"));
// You can also pass a string directly for metric IDs that don't have tags
let request_timer = registry.timer("server.requests");

// do some work and record some values.
for yak in find_some_yaks() {
    shave_yak(yak);
    yaks_shaved.inc();
}

// Grab a snapshot of the metrics currently registered and print their values:
for (id, metric) in &registry.metrics() {
    match metric {
        Metric::Counter(counter) => println!("{:?} is a counter with value {}", id, counter.count()),
        Metric::Timer(timer) => {
            let nanos = timer.snapshot().value(0.99);
            let duration = Duration::from_nanos(nanos as u64);
            println!("{:?} is a timer with 99th percentile {:?}", id, duration);
        }
        _ => {}
    }
}

# fn find_some_yaks() -> &'static [()] { &[] }
# fn shave_yak(_: &()) {}

Dependencies

~1.5MB
~28K SLoC

_