use metrics::Counter;
use super::super::MetricsManager;
#[derive(Clone)]
pub struct BackpressureMetrics {
pub events: Counter,
pub duration: Counter,
}
impl BackpressureMetrics {
#[must_use]
pub fn new(manager: &MetricsManager) -> Self {
Self {
events: manager.counter_with_labels(
"backpressure_events_total",
"Backpressure activation events",
&[],
"backpressure",
),
duration: manager.counter_with_labels(
"backpressure_duration_seconds_total",
"Cumulative time paused by backpressure",
&[],
"backpressure",
),
}
}
#[inline]
pub fn record_event(&self) {
self.events.increment(1);
}
#[inline]
pub fn record_duration(&self, seconds: f64) {
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
self.duration.increment(seconds as u64);
}
}