pub struct InFlightRequestsCounter { /* private fields */ }
Available on crate feature
metrics
only.Expand description
An atomic counter that keeps track of the number of in-flight requests.
This will normally combined with InFlightRequestsLayer
or InFlightRequests
which will
update the counter as requests arrive.
Implementations§
source§impl InFlightRequestsCounter
impl InFlightRequestsCounter
sourcepub async fn run_emitter<F, Fut>(self, interval: Duration, emit: F)where
F: FnMut(usize) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send,
pub async fn run_emitter<F, Fut>(self, interval: Duration, emit: F)where
F: FnMut(usize) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send,
Run a future every interval
which receives the current number of in-flight requests.
This can be used to send the current count to your metrics system.
This function will loop forever so normally it is called with tokio::spawn
:
use tower_http::metrics::in_flight_requests::InFlightRequestsCounter;
use std::time::Duration;
let counter = InFlightRequestsCounter::new();
tokio::spawn(
counter.run_emitter(Duration::from_secs(10), |count: usize| async move {
// Send `count` to metrics system.
}),
);
Trait Implementations§
source§impl Clone for InFlightRequestsCounter
impl Clone for InFlightRequestsCounter
source§fn clone(&self) -> InFlightRequestsCounter
fn clone(&self) -> InFlightRequestsCounter
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for InFlightRequestsCounter
impl Debug for InFlightRequestsCounter
source§impl Default for InFlightRequestsCounter
impl Default for InFlightRequestsCounter
source§fn default() -> InFlightRequestsCounter
fn default() -> InFlightRequestsCounter
Returns the “default value” for a type. Read more