pub struct ServiceCounters {
pub active_conns: AtomicU32,
pub total_requests: AtomicU64,
pub failed_requests: AtomicU64,
/* private fields */
}Expand description
Atomic counters that services increment in their hot paths.
The 1-minute sampler calls [snapshot_and_reset] to drain deltas and
produce a MetricSample.
Fields§
§active_conns: AtomicU32Current open connections (gauge — not reset on snapshot).
total_requests: AtomicU64Monotonic total requests since last snapshot.
failed_requests: AtomicU64Monotonic failed requests since last snapshot.
Implementations§
Source§impl ServiceCounters
impl ServiceCounters
pub fn new() -> Self
Sourcepub async fn record_request(&self, success: bool, latency_ms: f64)
pub async fn record_request(&self, success: bool, latency_ms: f64)
Record one completed request.
Increments total_requests unconditionally, and failed_requests when
success is false. The latency value is pushed into a buffer that
will be drained when the next sample is taken.
Sourcepub async fn snapshot_and_reset(&self) -> MetricSample
pub async fn snapshot_and_reset(&self) -> MetricSample
Take a point-in-time snapshot and reset the delta counters.
active_connsis read but not reset (it is a gauge).total_requestsandfailed_requestsare swapped to zero.- Latencies are drained and the p95 value is computed.
Trait Implementations§
Source§impl Debug for ServiceCounters
impl Debug for ServiceCounters
Auto Trait Implementations§
impl !Freeze for ServiceCounters
impl !RefUnwindSafe for ServiceCounters
impl !UnwindSafe for ServiceCounters
impl Send for ServiceCounters
impl Sync for ServiceCounters
impl Unpin for ServiceCounters
impl UnsafeUnpin for ServiceCounters
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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>
Wrap the input message
T in a tonic::Request