Histogram

Struct Histogram 

Source
pub struct Histogram { /* private fields */ }
Expand description

For tracking values. E.g. request latencies

Implementations§

Source§

impl Histogram

Source

pub fn new<T: Into<String>>(name: T) -> Histogram

Source

pub fn new_with_defaults<T: Into<String>>(name: T) -> Histogram

Examples found in repository?
examples/demo_run.rs (line 56)
48fn create_foo_metrics() -> (TelemetryTransmitter<FooLabel>, ProcessorMount) {
49    let mut foo_a_panel = Panel::named(FooLabel::A, "foo_a_panel");
50    foo_a_panel.add_counter(Counter::new_with_defaults("foo_a_counter"));
51    let mut gauge = Gauge::new_with_defaults("foo_a_gauge");
52    gauge.set_title("title");
53    gauge.set_description("description");
54    foo_a_panel.add_gauge(gauge);
55    foo_a_panel.add_meter(Meter::new_with_defaults("foo_a_meter"));
56    foo_a_panel.add_histogram(Histogram::new_with_defaults("foo_a_histogram"));
57    foo_a_panel.set_title("foo_1_panel_title");
58    foo_a_panel.set_description("foo_a_panel_description");
59
60    let mut foo_b_panel = Panel::new(FooLabel::B);
61    foo_b_panel.add_counter(Counter::new_with_defaults("foo_b_counter"));
62    let mut gauge = Gauge::new_with_defaults("foo_b_gauge").tracking(15);
63    gauge.set_title("title");
64    gauge.set_description("description");
65    foo_b_panel.add_gauge(gauge);
66    foo_b_panel.add_meter(Meter::new_with_defaults("foo_b_meter"));
67    foo_b_panel.add_histogram(Histogram::new_with_defaults("foo_b_histogram"));
68    foo_b_panel.set_title("foo_b_panel_title");
69    foo_b_panel.set_description("foo_b_panel_description");
70
71    let polled_counter = PolledCounter::new();
72    let mut polled_instrument =
73        PollingInstrument::new_with_defaults("polled_instrument_1", polled_counter);
74    polled_instrument.set_title("The polled counter 1");
75    polled_instrument.set_description("A counter that is increased when a snapshot is polled");
76    foo_b_panel.add_snapshooter(polled_instrument);
77
78    let staircase_timer = StaircaseTimer::new("staircase");
79    foo_b_panel.add_instrument(staircase_timer);
80
81    let mut cockpit = Cockpit::new("foo_cockpit");
82    cockpit.add_panel(foo_a_panel);
83    cockpit.add_panel(foo_b_panel);
84    cockpit.set_title("foo_cockpit_title");
85    cockpit.set_description("foo_cockpit_description");
86
87    let (tx, mut processor) = TelemetryProcessor::new_pair("processor_foo");
88
89    processor.add_cockpit(cockpit);
90
91    let mut group_processor = ProcessorMount::default();
92    group_processor.add_processor(processor);
93
94    (tx, group_processor)
95}
96
97fn create_bar_metrics() -> (TelemetryTransmitter<BarLabel>, ProcessorMount) {
98    let mut bar_a_panel = Panel::named(BarLabel::A, "bar_a_panel")
99        .counter(Counter::new_with_defaults("bar_a_counter"));
100    bar_a_panel.add_gauge(Gauge::new_with_defaults("bar_a_gauge"));
101    bar_a_panel.add_meter(Meter::new_with_defaults("bar_a_meter"));
102    bar_a_panel.add_histogram(Histogram::new_with_defaults("bar_a_histogram"));
103
104    let mut bar_a_cockpit = Cockpit::without_name();
105    bar_a_cockpit.add_panel(bar_a_panel);
106
107    let mut bar_b_panel = Panel::new(BarLabel::B);
108    bar_b_panel.add_counter(Counter::new_with_defaults("bar_b_counter"));
109    bar_b_panel.add_gauge(Gauge::new_with_defaults("bar_b_gauge"));
110    bar_b_panel.add_meter(Meter::new_with_defaults("bar_b_meter"));
111    bar_b_panel.add_histogram(Histogram::new_with_defaults("bar_b_histogram"));
112
113    let mut bar_b_cockpit = Cockpit::new("bar_b_cockpit");
114    bar_b_cockpit.add_panel(bar_b_panel);
115
116    let mut bar_c_panel = Panel::named(BarLabel::C, "bar_c_panel");
117    bar_c_panel.add_counter(Counter::new_with_defaults("bar_c_counter"));
118    bar_c_panel.add_gauge(Gauge::new_with_defaults("bar_c_gauge"));
119    bar_c_panel.add_meter(Meter::new_with_defaults("bar_c_meter"));
120    bar_c_panel.add_histogram(Histogram::new_with_defaults("bar_c_histogram"));
121
122    let mut bar_c_cockpit = Cockpit::new("bar_c_cockpit");
123    bar_c_cockpit.add_panel(bar_c_panel);
124
125    let (tx, mut processor) = TelemetryProcessor::new_pair_without_name();
126
127    processor.add_cockpit(bar_a_cockpit);
128    processor.add_cockpit(bar_b_cockpit);
129    processor.add_cockpit(bar_c_cockpit);
130
131    let mut group_processor1 = ProcessorMount::default();
132    group_processor1.add_processor(processor);
133
134    let mut group_processor2 = ProcessorMount::default();
135    group_processor2.add_processor(group_processor1);
136    group_processor2.set_name("group_processor_2");
137
138    let polled_counter = PolledCounter::new();
139    let mut polled_instrument =
140        PollingInstrument::new_with_defaults("polled_instrument_2", polled_counter);
141    polled_instrument.set_title("The polled counter 2");
142    polled_instrument.set_description("A counter that is increased when a snapshot is polled");
143
144    group_processor2.add_snapshooter(polled_instrument);
145
146    (tx, group_processor2)
147}
More examples
Hide additional examples
examples/panel.rs (line 26)
5fn main() {
6    let data_panel = Panel::named(AcceptAllLabels, "data_freshness")
7        .panel(
8            Panel::named(
9                (
10                    Metric::EffectiveDataTimestamp,
11                    Metric::EffectiveDataLatency,
12                    Metric::DataAgeAlert,
13                    Metric::DataAgeWarning,
14                ),
15                "effective",
16            )
17            .gauge(Gauge::new_with_defaults("epoch_ms").for_label(Metric::EffectiveDataTimestamp))
18            .gauge(
19                Gauge::new_with_defaults("latency_ms")
20                    .tracking(60)
21                    .group_values(true)
22                    .display_time_unit(TimeUnit::Milliseconds)
23                    .for_label(Metric::EffectiveDataLatency),
24            )
25            .histogram(
26                Histogram::new_with_defaults("latency_distribution_ms")
27                    .display_time_unit(TimeUnit::Milliseconds)
28                    .for_label(Metric::EffectiveDataLatency),
29            )
30            .handler(
31                StaircaseTimer::new_with_defaults("alert")
32                    .switch_off_after(Duration::from_secs(90))
33                    .for_label(Metric::DataAgeAlert),
34            )
35            .handler(
36                StaircaseTimer::new_with_defaults("warning")
37                    .switch_off_after(Duration::from_secs(90))
38                    .for_label(Metric::DataAgeWarning),
39            ),
40        )
41        .panel(
42            Panel::named((Metric::DbDataTimestamp, Metric::DbDataLatency), "db")
43                .gauge(Gauge::new_with_defaults("epoch_ms").for_label(Metric::DbDataTimestamp))
44                .gauge(
45                    Gauge::new_with_defaults("latency_ms")
46                        .tracking(60)
47                        .display_time_unit(TimeUnit::Milliseconds)
48                        .group_values(true)
49                        .for_label(Metric::DbDataLatency),
50                )
51                .histogram(
52                    Histogram::new_with_defaults("latency_distribution_ms")
53                        .display_time_unit(TimeUnit::Milliseconds)
54                        .for_label(Metric::DbDataLatency),
55                ),
56        )
57        .panel(
58            Panel::named(
59                (Metric::CacheDataTimestamp, Metric::CacheDataLatency),
60                "cache",
61            )
62            .gauge(Gauge::new_with_defaults("epoch_ms").for_label(Metric::CacheDataTimestamp))
63            .gauge(
64                Gauge::new_with_defaults("latency_ms")
65                    .tracking(60)
66                    .display_time_unit(TimeUnit::Milliseconds)
67                    .group_values(true)
68                    .for_label(Metric::CacheDataLatency),
69            )
70            .histogram(
71                Histogram::new_with_defaults("latency_distribution_ms")
72                    .display_time_unit(TimeUnit::Milliseconds)
73                    .for_label(Metric::CacheDataLatency),
74            ),
75        );
76
77    let mut snapshot = Snapshot::default();
78    data_panel.put_snapshot(&mut snapshot, false);
79    println!("{}", snapshot.to_default_json());
80}
Source

pub fn get_name(&self) -> &str

Source

pub fn set_name<T: Into<String>>(&mut self, name: T)

Source

pub fn name<T: Into<String>>(self, name: T) -> Self

Source

pub fn set_title<T: Into<String>>(&mut self, title: T)

Source

pub fn title<T: Into<String>>(self, title: T) -> Self

Source

pub fn set_description<T: Into<String>>(&mut self, description: T)

Source

pub fn description<T: Into<String>>(self, description: T) -> Self

Source

pub fn set_inactivity_limit(&mut self, limit: Duration)

Sets the maximum amount of time this histogram may be inactive until no more snapshots are taken

Default is no inactivity tracking.

Source

pub fn inactivity_limit(self, limit: Duration) -> Self

Sets the maximum amount of time this histogram may be inactive until no more snapshots are taken

Default is no inactivity tracking.

Source

pub fn set_reset_after_inactivity(&mut self, reset: bool)

Reset the histogram if inactivity tracking was enabled and the histogram was inactive.

The default is true. Only has an effect if a max_inactivity_duration is set.

Source

pub fn reset_after_inactivity(self, reset: bool) -> Self

Reset the histogram if inactivity tracking was enabled and the histogram was inactive.

The default is true. Only has an effect if a max_inactivity_duration is set.

Source

pub fn set_show_activity_state(&mut self, show: bool)

Set whether to show if the histogram is inactive or not if inactivity_limit is set.

The default is true. Only has an effect if a inactivity_limit is set.

Source

pub fn show_activity_state(self, show: bool) -> Self

Set whether to show if the histogram is inactive or not if inactivity_limit is set.

The default is true. Only has an effect if a inactivity_limit is set.

Source

pub fn set_display_time_unit(&mut self, display_time_unit: TimeUnit)

Source

pub fn display_time_unit(self, display_time_unit: TimeUnit) -> Self

Examples found in repository?
examples/panel.rs (line 27)
5fn main() {
6    let data_panel = Panel::named(AcceptAllLabels, "data_freshness")
7        .panel(
8            Panel::named(
9                (
10                    Metric::EffectiveDataTimestamp,
11                    Metric::EffectiveDataLatency,
12                    Metric::DataAgeAlert,
13                    Metric::DataAgeWarning,
14                ),
15                "effective",
16            )
17            .gauge(Gauge::new_with_defaults("epoch_ms").for_label(Metric::EffectiveDataTimestamp))
18            .gauge(
19                Gauge::new_with_defaults("latency_ms")
20                    .tracking(60)
21                    .group_values(true)
22                    .display_time_unit(TimeUnit::Milliseconds)
23                    .for_label(Metric::EffectiveDataLatency),
24            )
25            .histogram(
26                Histogram::new_with_defaults("latency_distribution_ms")
27                    .display_time_unit(TimeUnit::Milliseconds)
28                    .for_label(Metric::EffectiveDataLatency),
29            )
30            .handler(
31                StaircaseTimer::new_with_defaults("alert")
32                    .switch_off_after(Duration::from_secs(90))
33                    .for_label(Metric::DataAgeAlert),
34            )
35            .handler(
36                StaircaseTimer::new_with_defaults("warning")
37                    .switch_off_after(Duration::from_secs(90))
38                    .for_label(Metric::DataAgeWarning),
39            ),
40        )
41        .panel(
42            Panel::named((Metric::DbDataTimestamp, Metric::DbDataLatency), "db")
43                .gauge(Gauge::new_with_defaults("epoch_ms").for_label(Metric::DbDataTimestamp))
44                .gauge(
45                    Gauge::new_with_defaults("latency_ms")
46                        .tracking(60)
47                        .display_time_unit(TimeUnit::Milliseconds)
48                        .group_values(true)
49                        .for_label(Metric::DbDataLatency),
50                )
51                .histogram(
52                    Histogram::new_with_defaults("latency_distribution_ms")
53                        .display_time_unit(TimeUnit::Milliseconds)
54                        .for_label(Metric::DbDataLatency),
55                ),
56        )
57        .panel(
58            Panel::named(
59                (Metric::CacheDataTimestamp, Metric::CacheDataLatency),
60                "cache",
61            )
62            .gauge(Gauge::new_with_defaults("epoch_ms").for_label(Metric::CacheDataTimestamp))
63            .gauge(
64                Gauge::new_with_defaults("latency_ms")
65                    .tracking(60)
66                    .display_time_unit(TimeUnit::Milliseconds)
67                    .group_values(true)
68                    .for_label(Metric::CacheDataLatency),
69            )
70            .histogram(
71                Histogram::new_with_defaults("latency_distribution_ms")
72                    .display_time_unit(TimeUnit::Milliseconds)
73                    .for_label(Metric::CacheDataLatency),
74            ),
75        );
76
77    let mut snapshot = Snapshot::default();
78    data_panel.put_snapshot(&mut snapshot, false);
79    println!("{}", snapshot.to_default_json());
80}
Source

pub fn accept<L: Eq + Send + 'static, F: Into<LabelFilter<L>>>( self, accept: F, ) -> InstrumentAdapter<L, Self>

Source

pub fn for_label<L: Eq + Send + 'static>( self, label: L, ) -> InstrumentAdapter<L, Self>

Creates an InstrumentAdapter that makes this instrument react on observations on the given label.

Examples found in repository?
examples/panel.rs (line 28)
5fn main() {
6    let data_panel = Panel::named(AcceptAllLabels, "data_freshness")
7        .panel(
8            Panel::named(
9                (
10                    Metric::EffectiveDataTimestamp,
11                    Metric::EffectiveDataLatency,
12                    Metric::DataAgeAlert,
13                    Metric::DataAgeWarning,
14                ),
15                "effective",
16            )
17            .gauge(Gauge::new_with_defaults("epoch_ms").for_label(Metric::EffectiveDataTimestamp))
18            .gauge(
19                Gauge::new_with_defaults("latency_ms")
20                    .tracking(60)
21                    .group_values(true)
22                    .display_time_unit(TimeUnit::Milliseconds)
23                    .for_label(Metric::EffectiveDataLatency),
24            )
25            .histogram(
26                Histogram::new_with_defaults("latency_distribution_ms")
27                    .display_time_unit(TimeUnit::Milliseconds)
28                    .for_label(Metric::EffectiveDataLatency),
29            )
30            .handler(
31                StaircaseTimer::new_with_defaults("alert")
32                    .switch_off_after(Duration::from_secs(90))
33                    .for_label(Metric::DataAgeAlert),
34            )
35            .handler(
36                StaircaseTimer::new_with_defaults("warning")
37                    .switch_off_after(Duration::from_secs(90))
38                    .for_label(Metric::DataAgeWarning),
39            ),
40        )
41        .panel(
42            Panel::named((Metric::DbDataTimestamp, Metric::DbDataLatency), "db")
43                .gauge(Gauge::new_with_defaults("epoch_ms").for_label(Metric::DbDataTimestamp))
44                .gauge(
45                    Gauge::new_with_defaults("latency_ms")
46                        .tracking(60)
47                        .display_time_unit(TimeUnit::Milliseconds)
48                        .group_values(true)
49                        .for_label(Metric::DbDataLatency),
50                )
51                .histogram(
52                    Histogram::new_with_defaults("latency_distribution_ms")
53                        .display_time_unit(TimeUnit::Milliseconds)
54                        .for_label(Metric::DbDataLatency),
55                ),
56        )
57        .panel(
58            Panel::named(
59                (Metric::CacheDataTimestamp, Metric::CacheDataLatency),
60                "cache",
61            )
62            .gauge(Gauge::new_with_defaults("epoch_ms").for_label(Metric::CacheDataTimestamp))
63            .gauge(
64                Gauge::new_with_defaults("latency_ms")
65                    .tracking(60)
66                    .display_time_unit(TimeUnit::Milliseconds)
67                    .group_values(true)
68                    .for_label(Metric::CacheDataLatency),
69            )
70            .histogram(
71                Histogram::new_with_defaults("latency_distribution_ms")
72                    .display_time_unit(TimeUnit::Milliseconds)
73                    .for_label(Metric::CacheDataLatency),
74            ),
75        );
76
77    let mut snapshot = Snapshot::default();
78    data_panel.put_snapshot(&mut snapshot, false);
79    println!("{}", snapshot.to_default_json());
80}
Source

pub fn for_labels<L: Eq + Send + 'static>( self, labels: Vec<L>, ) -> InstrumentAdapter<L, Self>

Creates an InstrumentAdapter that makes this instrument react on observations with the given labels.

If labels is empty the instrument will not react to any observations

Source

pub fn for_all_labels<L: Eq + Send + 'static>( self, ) -> InstrumentAdapter<L, Self>

Creates an InstrumentAdapter that makes this instrument react on all observations.

Source

pub fn for_labels_by_predicate<L, P>( self, label_predicate: P, ) -> InstrumentAdapter<L, Self>
where L: Eq + Send + 'static, P: Fn(&L) -> bool + Send + 'static,

Creates an InstrumentAdapter that makes this instrument react on observations with labels specified by the predicate.

Source

pub fn adapter<L: Eq + Send + 'static>(self) -> InstrumentAdapter<L, Self>

Creates an InstrumentAdapter that makes this instrument to no observations.

Trait Implementations§

Source§

impl Descriptive for Histogram

Source§

fn title(&self) -> Option<&str>

Source§

fn description(&self) -> Option<&str>

Source§

impl PutsSnapshot for Histogram

Source§

fn put_snapshot(&self, into: &mut Snapshot, descriptive: bool)

Puts the current snapshot values into the given Snapshot thereby following the guidelines of PutsSnapshot.
Source§

impl Updates for Histogram

Source§

fn update(&mut self, with: &Update) -> usize

Update the internal state according to the given Update. Read more
Source§

impl Instrument for Histogram

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V