pub struct Metrics<TBuildHasher = RandomState> { /* private fields */ }
Expand description
A Metrics encapsulates a unit of work.
It is a record of the interesting things that happened during that unit, and the things that describe it.
A web request handler, grpc service rpc implementation or periodic job’s execution is a unit of work you should have a Metrics for.
Metrics does not deal in things like “gauges” or “counters.” It is more like a single-level trace; it works with concrete observations rather than exposing your code to aggregators.
Metrics objects are emitted through a reporter chain when they are Dropped. It is at that point that aggregation, if you’ve configured any, is performed.
Your code is responsible for putting the details of interest into the Metrics object as it encounters interesting details. You just record what you want to.
Generally prefer to record dimensions as early as possible, in case you early-out somewhere; in this way you’ll have more information in those cases.
Implementations§
Source§impl<TBuildHasher> Metrics<TBuildHasher>where
TBuildHasher: BuildHasher,
impl<TBuildHasher> Metrics<TBuildHasher>where
TBuildHasher: BuildHasher,
Sourcepub fn dimension(&mut self, name: impl Into<Name>, value: impl Into<Dimension>)
pub fn dimension(&mut self, name: impl Into<Name>, value: impl Into<Dimension>)
Record a dimension name and value pair - last write per metrics object wins!
Sourcepub fn measurement(
&mut self,
name: impl Into<Name>,
value: impl Into<Observation>,
)
pub fn measurement( &mut self, name: impl Into<Name>, value: impl Into<Observation>, )
Record a measurement name and value pair - last write per metrics object wins!
Sourcepub fn distribution(
&mut self,
name: impl Into<Name>,
value: impl Into<Distribution>,
)
pub fn distribution( &mut self, name: impl Into<Name>, value: impl Into<Distribution>, )
Record a distribution name and value pair - last write per metrics object wins! Check out t-digests if you’re using a goodmetrics + timescale downstream.
Sourcepub fn sum(&mut self, name: impl Into<Name>, value: impl Into<i64>)
pub fn sum(&mut self, name: impl Into<Name>, value: impl Into<i64>)
Record a sum. Repeated reports add together in this object.
Aggregation: Locally summed per report period.
Sourcepub fn time(&mut self, timer_name: impl Into<Name>) -> Timer
pub fn time(&mut self, timer_name: impl Into<Name>) -> Timer
Record a time distribution in nanoseconds. Check out t-digests if you’re using a goodmetrics + timescale downstream.
The returned Timer is a scope guard.
Sourcepub fn guarded_dimension(
&mut self,
name: impl Into<Name>,
default: impl Into<Dimension>,
) -> DimensionGuard
pub fn guarded_dimension( &mut self, name: impl Into<Name>, default: impl Into<Dimension>, ) -> DimensionGuard
A dimension that you set a default for in case you drop early or something.
Sourcepub fn restart(&mut self)
pub fn restart(&mut self)
Clear the structure in preparation for reuse without allocation. You still need to set the right behaviors and start times.
Sourcepub fn has_behavior(&self, behavior: MetricsBehavior) -> bool
pub fn has_behavior(&self, behavior: MetricsBehavior) -> bool
Check if this metrics has that behavior.
Sourcepub unsafe fn add_behavior(&mut self, behavior: MetricsBehavior)
pub unsafe fn add_behavior(&mut self, behavior: MetricsBehavior)
§Safety
This function is intended to be used by MetricsFactories while creating new instances. It is not intended for use outside of infrastructure code. It is exposed in case you have something special you need to do with your allocator. You shouldn’t call this unless you know you need to and provide your own guarantees about when the behavior is added and whether it’s legal & valid
Sourcepub unsafe fn set_raw_behavior(&mut self, behavior: u32)
pub unsafe fn set_raw_behavior(&mut self, behavior: u32)
§Safety
This function is intended to be used by MetricsFactories while creating new instances. It is not intended for use outside of infrastructure code. It is exposed in case you have something special you need to do with your allocator. You shouldn’t call this unless you know you need to and provide your own guarantees about when the behavior is added and whether it’s legal & valid
Trait Implementations§
Source§impl<TBuildHasher: BuildHasher + Default + Send> AsMut<Metrics<TBuildHasher>> for CachedMetrics<TBuildHasher>
impl<TBuildHasher: BuildHasher + Default + Send> AsMut<Metrics<TBuildHasher>> for CachedMetrics<TBuildHasher>
Source§impl<TBuildHasher: BuildHasher + Default + Send> AsRef<Metrics<TBuildHasher>> for CachedMetrics<TBuildHasher>
impl<TBuildHasher: BuildHasher + Default + Send> AsRef<Metrics<TBuildHasher>> for CachedMetrics<TBuildHasher>
Auto Trait Implementations§
impl<TBuildHasher> Freeze for Metrics<TBuildHasher>where
TBuildHasher: Freeze,
impl<TBuildHasher> RefUnwindSafe for Metrics<TBuildHasher>where
TBuildHasher: RefUnwindSafe,
impl<TBuildHasher> Send for Metrics<TBuildHasher>where
TBuildHasher: Send,
impl<TBuildHasher> Sync for Metrics<TBuildHasher>where
TBuildHasher: Sync,
impl<TBuildHasher> Unpin for Metrics<TBuildHasher>where
TBuildHasher: Unpin,
impl<TBuildHasher> UnwindSafe for Metrics<TBuildHasher>where
TBuildHasher: UnwindSafe,
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> 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