mirror of
https://github.com/tokio-rs/axum.git
synced 2025-09-27 13:00:39 +00:00
examples/prometheus-metrics: run upkeep task (#3430)
Co-authored-by: David Mládek <david.mladek.cz@gmail.com>
This commit is contained in:
parent
a57935c039
commit
4b0590b30e
@ -81,14 +81,24 @@ fn setup_metrics_recorder() -> PrometheusHandle {
|
||||
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0,
|
||||
];
|
||||
|
||||
PrometheusBuilder::new()
|
||||
let recorder_handle = PrometheusBuilder::new()
|
||||
.set_buckets_for_metric(
|
||||
Matcher::Full("http_requests_duration_seconds".to_string()),
|
||||
EXPONENTIAL_SECONDS,
|
||||
)
|
||||
.unwrap()
|
||||
.install_recorder()
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
let upkeep_handle = recorder_handle.clone();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||
upkeep_handle.run_upkeep();
|
||||
}
|
||||
});
|
||||
|
||||
recorder_handle
|
||||
}
|
||||
|
||||
async fn track_metrics(req: Request, next: Next) -> impl IntoResponse {
|
||||
|
Loading…
x
Reference in New Issue
Block a user