auth dns over atproto
at main 30 lines 977 B view raw
1use axum::extract::State; 2use axum::http::StatusCode; 3use axum::response::IntoResponse; 4use axum::routing::get; 5use axum::Router; 6 7pub use metrics_exporter_prometheus::PrometheusHandle; 8 9use metrics_exporter_prometheus::PrometheusBuilder; 10 11/// Initialize the global metrics recorder and return a handle for rendering. 12pub fn init() -> Result<PrometheusHandle, metrics_exporter_prometheus::BuildError> { 13 PrometheusBuilder::new().install_recorder() 14} 15 16/// Axum handler that renders all registered metrics in Prometheus exposition format. 17pub async fn metrics_handler(State(handle): State<PrometheusHandle>) -> impl IntoResponse { 18 ( 19 StatusCode::OK, 20 [("content-type", "text/plain; version=0.0.4; charset=utf-8")], 21 handle.render(), 22 ) 23} 24 25/// Returns a minimal axum router with just `GET /metrics`. 26pub fn router(handle: PrometheusHandle) -> Router { 27 Router::new() 28 .route("/metrics", get(metrics_handler)) 29 .with_state(handle) 30}