Expand description
Metrics for applications and libraries.
A metric is defined once with metric!: its name, kind, unit, description
and the tags it may carry. The definition is a handle that records. It is
also registered automatically: registry lists it without the program
doing anything, provided the linker keeps it. A definition whose handle the
program refers to is always kept. See registry for the other cases.
Recordings go to a Recorder. Stats is the one that aggregates: one
point per series per window, with counters summed, gauges and states
keeping their last value and timers kept as a Histogram. A flush hands
the closed windows to a Sink as a Batch.
use std::sync::Arc;
use std::time::Duration;
use fibre_stats::{metric, tags, Stats, StatsConfig, VecSink};
metric! {
/// Requests answered.
#[tags("status")]
pub static REQUESTS: Counter = "http.requests";
/// Time to answer one request.
pub static LATENCY: Timer = "http.latency";
}
let stats = Stats::new(StatsConfig::default());
REQUESTS.add_to(&stats, 1, tags!("status" => "ok"));
LATENCY.record_to(&stats, Duration::from_millis(3), tags!());
let batch = stats.drain(true);
assert_eq!(batch.series.len(), 2);
assert!(fibre_stats::registry().any(|m| m.name == "http.requests"));With the global recorder installed, the handles need no recorder:
fibre_stats::set_global(Arc::new(stats.clone()))?;
REQUESTS.incr(tags!("status" => "ok"));Re-exports§
pub use collect::Collector;pub use error::CollectError;pub use error::SetGlobalError;pub use histogram::Histogram;pub use metric::Counter;pub use metric::Gauge;pub use metric::Kind;pub use metric::Metric;pub use metric::MetricAttr;pub use metric::State;pub use metric::Timer;pub use metric::TimerGuard;pub use metric::Unit;pub use metric::find;pub use metric::registry;pub use recorder::Clock;pub use recorder::Context;pub use recorder::Noop;pub use recorder::Observation;pub use recorder::Recorder;pub use recorder::RecorderExt;pub use recorder::Sample;pub use recorder::global;pub use recorder::global_arc;pub use recorder::set_global;pub use recorder::SystemClock;pub use recorder::XsClock;pub use sink::Batch;pub use sink::Dropped;pub use sink::Points;pub use sink::SeriesBatch;pub use sink::Sink;pub use sink::VecSink;pub use stats::CollectorId;pub use stats::Refusal;pub use stats::RefusalReason;pub use stats::Stats;pub use stats::StatsConfig;pub use tag::Name;pub use tag::Tag;pub use tag::Tags;pub use value::Encoding;pub use value::EnumState;pub use value::IntValue;pub use value::Normalized;pub use value::NumberValue;pub use value::Percent;pub use value::Ratio32;pub use value::StatValue;pub use value::StateValue;
Modules§
- collect
- Collectors read a value on a schedule and record it.
- error
- histogram
- A histogram of durations with exponential buckets.
- metric
- Metric definitions and the handles that record through them.
- recorder
- Where recordings go.
- sink
- What a
Statshands on when it flushes. - stats
- The recorder that aggregates.
- tag
- Tags name the series a value belongs to.
- value
- The values a metric can hold.
Macros§
- metric
- Defines metrics. Use it at module level.
- state_
enum - Defines an enum that is reported as a state.
- tags
- Builds a
Tagsfromname => valuepairs.