pub struct Metric { /* private fields */ }
Expand description
A metric.
Metrics represent the measurement of a particular quantity at a particular point in time. Several different metric types exist that provide different views into the underlying quantity: counters for representing the quantities that are aggregated/totaled over time, gauges for tracking the latest value of a quantity, and histograms for tracking the distribution of a quantity.
§Structure
A metric is composed of three parts: the context, the value, and the metadata.
The context represents the “full” name of the metric, which includes not only the name (e.g. http_requests_total
),
but the tags as well. Effectively, a context is meant to be a unique name for a metric.
The value is precisely what it sounds like: the value of the metric. The value holds both the metric type and the measurement (or measurements) tied to that metric type. This ensures that the measurement(s) are always represented correctly for the given metric type.
The metadata contains ancillary data related to the metric, such as the timestamp, sample rate, and origination information like hostname and sender.
Implementations§
Source§impl Metric
impl Metric
Sourcepub fn counter<C, V>(context: C, values: V) -> Self
pub fn counter<C, V>(context: C, values: V) -> Self
Creates a counter metric from the given context and value(s).
Default metadata will be used.
Sourcepub fn gauge<C, V>(context: C, values: V) -> Self
pub fn gauge<C, V>(context: C, values: V) -> Self
Creates a gauge metric from the given context and value(s).
Default metadata will be used.
Sourcepub fn rate<C, V>(context: C, values: V, interval: Duration) -> Self
pub fn rate<C, V>(context: C, values: V, interval: Duration) -> Self
Creates a rate metric from the given context and value(s).
Default metadata will be used.
Sourcepub fn set<C, V>(context: C, values: V) -> Self
pub fn set<C, V>(context: C, values: V) -> Self
Creates a set metric from the given context and value(s).
Default metadata will be used.
Sourcepub fn histogram<C, V>(context: C, values: V) -> Self
pub fn histogram<C, V>(context: C, values: V) -> Self
Creates a histogram metric from the given context and value(s).
Default metadata will be used.
Sourcepub fn distribution<C, V>(context: C, values: V) -> Self
pub fn distribution<C, V>(context: C, values: V) -> Self
Creates a distribution metric from the given context and value(s).
Default metadata will be used.
Sourcepub fn context_mut(&mut self) -> &mut Context
pub fn context_mut(&mut self) -> &mut Context
Gets a mutable reference to the context.
Sourcepub fn values(&self) -> &MetricValues
pub fn values(&self) -> &MetricValues
Gets a reference to the values.
Sourcepub fn values_mut(&mut self) -> &mut MetricValues
pub fn values_mut(&mut self) -> &mut MetricValues
Gets a mutable reference to the values.
Sourcepub fn metadata(&self) -> &MetricMetadata
pub fn metadata(&self) -> &MetricMetadata
Gets a reference to the metadata.
Sourcepub fn metadata_mut(&mut self) -> &mut MetricMetadata
pub fn metadata_mut(&mut self) -> &mut MetricMetadata
Gets a mutable reference to the metadata.
Sourcepub fn into_parts(self) -> (Context, MetricValues, MetricMetadata)
pub fn into_parts(self) -> (Context, MetricValues, MetricMetadata)
Consumes the metric and returns the individual parts.
Sourcepub fn from_parts(
context: Context,
values: MetricValues,
metadata: MetricMetadata,
) -> Self
pub fn from_parts( context: Context, values: MetricValues, metadata: MetricMetadata, ) -> Self
Creates a Metric
from the given parts.
Trait Implementations§
impl StructuralPartialEq for Metric
Auto Trait Implementations§
impl Freeze for Metric
impl !RefUnwindSafe for Metric
impl Send for Metric
impl Sync for Metric
impl Unpin for Metric
impl !UnwindSafe for Metric
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Track for T
impl<T> Track for T
§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked
wrapper. Read more§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked
wrapper. Read more