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
impl EventMetrics
Sourcepub fn name(&self) -> &EventName
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());
}Sourcepub fn count(&self) -> u64
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());
}Sourcepub fn sum(&self) -> Magnitude
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());
}Sourcepub fn mean(&self) -> Magnitude
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());
}Sourcepub fn histogram(&self) -> Option<&Histogram>
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
impl Debug for EventMetrics
Auto Trait Implementations§
impl Freeze for EventMetrics
impl RefUnwindSafe for EventMetrics
impl Send for EventMetrics
impl Sync for EventMetrics
impl Unpin for EventMetrics
impl UnwindSafe for EventMetrics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more