diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-01-03 17:57:35 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-01-03 17:57:35 +0100 |
commit | 5baace1803787aee956861704124e0c46e0ba029 (patch) | |
tree | 136ee774f6c8568a2c75437143d2e2834fa2b812 | |
parent | cfde64c7c9fa1ed3beb3382f34af75e3a96b5c20 (diff) |
Move handler to /metrics and add basic index handler
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/main.rs | 11 |
1 files 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<Mutex<MpdClient>>, 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<Mutex<MpdClient>>, 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<Mutex<MpdClient>>, req: HttpRequest) -> impl } } -async fn index_handler(mpd_data: web::Data<Mutex<MpdClient>>) -> Result<String, ApplicationError> { +async fn metrics_handler(mpd_data: web::Data<Mutex<MpdClient>>) -> Result<String, ApplicationError> { 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() |