Skip to main content

witchcraft_metrics/
lib.rs

1// Copyright 2019 Palantir Technologies, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//! A general-purpose metrics library.
15//!
16//! The design of the crate is based fairly closely off of the [Dropwizard Metrics] library from the Java ecosystem.
17//!
18//! # Examples
19//!
20//! ```
21//! use witchcraft_metrics::{MetricRegistry, MetricId, Metric};
22//! use std::time::Duration;
23//!
24//! // A `MetricRegistry` stores metrics.
25//! let registry = MetricRegistry::new();
26//!
27//! // Metrics are identified by an ID, which consists of a name and set of "tags"
28//! let yaks_shaved = registry.counter(MetricId::new("shavings").with_tag("animal", "yak"));
29//! // You can also pass a string directly for metric IDs that don't have tags
30//! let request_timer = registry.timer("server.requests");
31//!
32//! // do some work and record some values.
33//! for yak in find_some_yaks() {
34//!     shave_yak(yak);
35//!     yaks_shaved.inc();
36//! }
37//!
38//! // Grab a snapshot of the metrics currently registered and print their values:
39//! for (id, metric) in &registry.metrics() {
40//!     match metric {
41//!         Metric::Counter(counter) => println!("{:?} is a counter with value {}", id, counter.count()),
42//!         Metric::Timer(timer) => {
43//!             let nanos = timer.snapshot().value(0.99);
44//!             let duration = Duration::from_nanos(nanos as u64);
45//!             println!("{:?} is a timer with 99th percentile {:?}", id, duration);
46//!         }
47//!         _ => {}
48//!     }
49//! }
50//!
51//! # fn find_some_yaks() -> &'static [()] { &[] }
52//! # fn shave_yak(_: &()) {}
53//! ```
54//!
55//! [Dropwizard Metrics]: https://github.com/dropwizard/metrics
56#![warn(missing_docs)]
57
58pub use crate::clock::*;
59pub use crate::counter::*;
60pub use crate::gauge::*;
61pub use crate::histogram::*;
62pub use crate::meter::*;
63pub use crate::metric_id::*;
64pub use crate::registry::*;
65pub use crate::reservoir::*;
66pub use crate::timer::*;
67
68mod clock;
69mod counter;
70mod gauge;
71mod histogram;
72mod meter;
73mod metric_id;
74mod registry;
75mod reservoir;
76mod timer;