use axum::extract::State; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::routing::get; use axum::Router; pub use metrics_exporter_prometheus::PrometheusHandle; use metrics_exporter_prometheus::PrometheusBuilder; /// Initialize the global metrics recorder and return a handle for rendering. pub fn init() -> Result { PrometheusBuilder::new().install_recorder() } /// Axum handler that renders all registered metrics in Prometheus exposition format. pub async fn metrics_handler(State(handle): State) -> impl IntoResponse { ( StatusCode::OK, [("content-type", "text/plain; version=0.0.4; charset=utf-8")], handle.render(), ) } /// Returns a minimal axum router with just `GET /metrics`. pub fn router(handle: PrometheusHandle) -> Router { Router::new() .route("/metrics", get(metrics_handler)) .with_state(handle) }