Struct dipstick::AppLabel

source ·
pub struct AppLabel;
Expand description

Handle metric labels for the whole application (globals). App scope labels have the lowest lookup priority and serve as a fallback to other scopes.

Implementations§

source§

impl AppLabel

source

pub fn get(key: &str) -> Option<Arc<String>>

Retrieve a value from the app scope.

source

pub fn set<S: Into<String>>(key: S, value: S)

Set a new value for the app scope. Replaces any previous value for the key.

Examples found in repository?
examples/text_format_label.rs (line 37)
32
33
34
35
36
37
38
39
40
41
42
43
fn main() {
    let counter = Stream::write_to_stderr()
        .formatting(MyFormat)
        .metrics()
        .counter("counter_a");
    AppLabel::set("abc", "xyz");
    loop {
        // report some metric values from our "application" loop
        counter.count(11);
        sleep(Duration::from_millis(500));
    }
}
More examples
Hide additional examples
examples/prometheus_labels.rs (line 12)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let metrics = Prometheus::push_to("http://localhost:9091/metrics/job/prometheus_example")
        .expect("Prometheus Socket")
        .named("my_app")
        .metrics();

    AppLabel::set("abc", "456");
    ThreadLabel::set("xyz", "123");

    loop {
        metrics.counter("counter_a").count(123);
        metrics.timer("timer_a").interval_us(2000000);
        std::thread::sleep(Duration::from_millis(40));
    }
}
source

pub fn unset(key: &str)

Unset a value for the app scope. Has no effect if key was not set.

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>,

§

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>,

§

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.