44 lines
2.3 KiB
Rust
44 lines
2.3 KiB
Rust
/********************************************************************************
|
|
* Prometheus exporter for monitoring network connectivity using icmp pings *
|
|
* *
|
|
* Copyright (C) 2019-2022 Jan Christian Grünhage *
|
|
* Copyright (C) 2020-2021 Famedly GmbH *
|
|
* *
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
* License, or (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU Affero General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
********************************************************************************/
|
|
use crate::config::Config;
|
|
use anyhow::Result;
|
|
use axum::{response::IntoResponse, routing::get, Router, Server};
|
|
use log::info;
|
|
use metrics_exporter_prometheus::PrometheusHandle;
|
|
|
|
async fn metrics(handle: PrometheusHandle) -> impl IntoResponse {
|
|
handle.render()
|
|
}
|
|
|
|
pub(crate) async fn start_serving_metrics(config: &Config, handle: PrometheusHandle) -> Result<()> {
|
|
let app = Router::new()
|
|
.route(
|
|
"/metrics",
|
|
get({
|
|
let handle = handle.clone();
|
|
move || metrics(handle)
|
|
}),
|
|
)
|
|
.route("/health", get(|| async { "" }));
|
|
let serve_future = Server::bind(&config.listener).serve(app.into_make_service());
|
|
info!("Listening on {}", &config.listener);
|
|
Ok(serve_future.await?)
|
|
}
|