From 5baace1803787aee956861704124e0c46e0ba029 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Jan 2021 17:57:35 +0100 Subject: Move handler to /metrics and add basic index handler Signed-off-by: Matthias Beyer --- src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index f0048aa..a06ee75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,13 @@ struct Opt { struct PrometheusOptions {} async fn index(mpd_data: web::Data>, req: HttpRequest) -> impl Responder { - match index_handler(mpd_data).await { + HttpResponse::build(StatusCode::OK) + .content_type("text/text; charset=utf-8") + .body(String::from("Running")) +} + +async fn metrics(mpd_data: web::Data>, req: HttpRequest) -> impl Responder { + match metrics_handler(mpd_data).await { Ok(text) => { HttpResponse::build(StatusCode::OK) .content_type("text/text; charset=utf-8") @@ -80,7 +86,7 @@ async fn index(mpd_data: web::Data>, req: HttpRequest) -> impl } } -async fn index_handler(mpd_data: web::Data>) -> Result { +async fn metrics_handler(mpd_data: web::Data>) -> Result { let mut mpd = mpd_data.lock().unwrap(); let stats = mpd.stats().await?; @@ -125,6 +131,7 @@ async fn main() -> Result<(), ApplicationError> { .app_data(mpd.clone()) // add shared state .wrap(middleware::Logger::default()) .route("/", web::get().to(index)) + .route("/metrics", web::get().to(metrics)) }) .bind(prometheus_bind_addr)? .run() -- cgit v1.2.3