[−][src]Crate witchcraft_metrics
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 ®istry.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); } _ => {} } }
Structs
Counter | A metric which counts a value. |
ExponentiallyDecayingReservoir | A reservoir which exponentially weights in favor of recent values. |
Histogram | A metric tracking a statistical distribution of values. |
Meter | A metric tracking the rate of occurrence of an event. |
MetricId | An identifier of a metric. |
MetricRegistry | A collection of metrics. |
Metrics | A snapshot of the metrics in a registry. |
MetricsIter | An iterator over metrics and their IDs. |
Tags | The tags associated with a metric ID. |
TagsIter | An iterator over the key-value pairs of a metric ID's tags. |
Time | A guard type which reports the time elapsed since its creation to a timer when it drops. |
Timer | A metric tracking the duration and rate of events. |
Enums
Metric | An enum of all metric types. |
Traits
Gauge | A generalized metric which computes an arbitrary value. |
Reservoir | A statistically representative subset of a set of values. |
Snapshot | Statistics about a set of values. |