Struct EventMetrics

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

A human- and machine-readable report about observed occurrences of a single event.

Part of a collected Report,

Implementations§

Source§

impl EventMetrics

Source

pub fn name(&self) -> &EventName

The name of the event associated with these metrics.

§Example
use nm::{Event, Report};

thread_local! {
    static HTTP_REQUESTS: Event = Event::builder()
        .name("http_requests")
        .build();
}

HTTP_REQUESTS.with(|e| e.observe_once());
let report = Report::collect();

for event in report.events() {
    println!("Event name: {}", event.name());
}
Source

pub fn count(&self) -> u64

Total number of occurrences that have been observed.

§Example
use nm::{Event, Report};

thread_local! {
    static HTTP_REQUESTS: Event = Event::builder()
        .name("http_requests")
        .build();
}

HTTP_REQUESTS.with(|e| e.observe_once());
HTTP_REQUESTS.with(|e| e.observe_once());
let report = Report::collect();

for event in report.events() {
    println!("Total count: {}", event.count());
}
Source

pub fn sum(&self) -> Magnitude

Sum of the magnitudes of all observed occurrences.

§Example
use nm::{Event, Report};

thread_local! {
    static SENT_BYTES: Event = Event::builder()
        .name("sent_bytes")
        .build();
}

SENT_BYTES.with(|e| e.observe(1024));
SENT_BYTES.with(|e| e.observe(2048));
let report = Report::collect();

for event in report.events() {
    println!("Total bytes: {}", event.sum());
}
Source

pub fn mean(&self) -> Magnitude

Mean magnitude of all observed occurrences.

If there are no observations, this will be zero.

§Example
use nm::{Event, Report};

thread_local! {
    static RESPONSE_TIME: Event = Event::builder()
        .name("response_time_ms")
        .build();
}

RESPONSE_TIME.with(|e| e.observe(100));
RESPONSE_TIME.with(|e| e.observe(200));
let report = Report::collect();

for event in report.events() {
    println!("Average response time: {}ms", event.mean());
}
Source

pub fn histogram(&self) -> Option<&Histogram>

The histogram of observed magnitudes (if configured).

None if the event was not configured to generate a histogram.

§Example
use nm::{Event, Magnitude, Report};

const RESPONSE_TIME_BUCKETS_MS: &[Magnitude] = &[10, 50, 100, 500];

thread_local! {
    static HTTP_RESPONSE_TIME_MS: Event = Event::builder()
        .name("http_response_time_ms")
        .histogram(RESPONSE_TIME_BUCKETS_MS)
        .build();
}

HTTP_RESPONSE_TIME_MS.with(|e| e.observe(75));
let report = Report::collect();

for event in report.events() {
    if let Some(histogram) = event.histogram() {
        println!("Histogram for {}", event.name());
        for (bucket_upper_bound, count) in histogram.buckets() {
            println!("  ≤{}: {}", bucket_upper_bound, count);
        }
    }
}

Trait Implementations§

Source§

impl Debug for EventMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for EventMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.