use rocket::{get, routes}; pub fn rocket() -> rocket::Rocket { rocket::build().mount("/", routes![metrics,]) } #[get("/metrics")] fn metrics() -> Result { Ok( prometheus::TextEncoder::new() .encode_to_string(&prometheus::default_registry().gather())?, ) } enum ServerError { Prometheus, } impl From for ServerError { fn from(_: prometheus::Error) -> Self { Self::Prometheus } } impl<'a> rocket::response::Responder<'a, 'a> for ServerError { fn respond_to(self, _: &'a rocket::Request<'_>) -> rocket::response::Result<'a> { Err(match self { ServerError::Prometheus => rocket::http::Status::InternalServerError, }) } }