measured/docs/guide.rs
1//! The guide to terminology used in this crate, and how it all fits together.
2//!
3//! # `Metric`
4//!
5//! A [`Metric`](crate::Metric) represents a single aggregated quantity.
6//!
7//! ## `Counter`
8//!
9//! A [`Counter`](crate::Counter) is a `Metric` that typically represents how many events have been observed throughout the lifetime of the program.
10//!
11//! For instance:
12//! * Total number of HTTP requests
13//! * Total number of error responses
14//!
15//! When sampled over time, the increase can be used to calculate the rate-per-second of each event.
16//!
17//! ## `Gauge`
18//!
19//! A [`Gauge`](crate::Gauge) is a `Metric` that typically represents the size of a resource as used by the program at the current point in time.
20//!
21//! For instance:
22//! * Memory usage in bytes.
23//! * Number of idle database connections in a connection pool.
24//! * Number of active tasks
25//!
26//! ## `Histogram`
27//!
28//! A [`Histogram`](crate::Histogram) is a `Metric` that represents dynamically sized observations throughout the lifetime of the program.
29//!
30//! For instance:
31//! * Latencies for DB queries
32//! * Sizes of HTTP request bodies
33//!
34//! When sampled over time, the histogram bucket increases can be used to calculate quantiles, such as P50s, P99s, etc.
35//!
36//! # `MetricVec`
37//!
38//! A [`MetricVec`](crate::MetricVec) represents multiple `Metric`s, keyed by a group of labels.
39//!
40//! These labels are typically used to refine the metric to a more specific case. For instance:
41//! * a [`CounterVec`](crate::CounterVec) could represent the total number of HTTP requests **by resource path**
42//! * a [`GaugeVec`](crate::GaugeVec) could represent the number of currently active tasks **by task type**
43//! * a [`HistogramVec`](crate::HistogramVec) could represent the latencies of DB queries **by logical query name**
44//!
45//! # `MetricGroup`
46//!
47//! As the name implies, a [`MetricGroup`](crate::MetricGroup) is a logical group of `Metric`s or `MetricVec`s.
48//! These groups can be as small or as large as necessary for the needs of your library or application.
49//!
50//! Groups can be nested with other groups, with the ability to namespace the metrics within the group as well,
51//! for better isolation of metrics exposed by a library.
52//!
53//! # Labels
54//!
55//! ## `LabelValue`
56//!
57//! A [`LabelValue`](crate::label::LabelValue) is a value that can be encoded in a label position.
58//!
59//! ### `FixedCardinalityLabel`
60//!
61//! A [`FixedCardinalityLabel`](crate::FixedCardinalityLabel) is a `LabelValue` that has a fixed 'cardinality', i.e. a fixed number of possible values.
62//! This is typically represented via a unit `enum` where each variant represents one of the fixed possible values.
63//!
64//! ## `LabelSet`
65//!
66//! This is a unique quirk of this crate. A [`LabelSet`](crate::label::LabelSet) is needed in order to convert an arbitrary `LabelValue` into
67//! a specific integer value. This is a necessary feature in order to unlock some of the impressive performance gains that this library unlocks.
68//!
69//! ### `FixedCardinalitySet`
70//!
71//! A [`FixedCardinalitySet`](crate::label::FixedCardinalitySet) is a `LabelSet` that can encode a fixed number of possible `LabelValue`s.
72//! This is slightly different to `FixedCardinalityLabel` because a `FixedCardinalityLabel` must know all possible values at compile time,
73//! whereas a `FixedCardinalitySet` must only know all possible values at startup time.
74//!
75//! ### `DynamicLabelSet`
76//!
77//! A [`DynamicLabelSet`](crate::label::DynamicLabelSet) is a `LabelSet` that can encode any number of possible `LabelValue`s.
78//! Values do not need to be provided up front. Values will be inserted into the set with a consistent index value when they are discovered.
79//! Because of this, they end up being the most expensive set option. They are necessary for use cases where values are only known post-startup,
80//! or just useful for convenience where some performance loss is acceptable.
81//!
82//! # `LabelGroup`
83//!
84//! As the name implies, a [`LabelGroup`](crate::LabelGroup) is a group of labels which can be used as the key to a `MetricVec`.
85//!
86//! # `LabelGroupSet`
87//!
88//! A [`LabelGroupSet`](crate::label::LabelGroupSet) is to a `LabelGroup`, as a `LabelSet` is to a `LabelValue`.