diff --git a/rust/relay/src/main.rs b/rust/relay/src/main.rs index fcfaa39b8..effc5c1d3 100644 --- a/rust/relay/src/main.rs +++ b/rust/relay/src/main.rs @@ -32,6 +32,11 @@ struct Args { /// Must not be a wildcard-address. #[arg(long, env)] listen_ip4_addr: Ipv4Addr, + /// The address of the local interface where we should serve the prometheus metrics. + /// + /// The metrics will be available at `http:///metrics`. + #[arg(long, env)] + metrics_addr: Option, /// The websocket URL of the portal server to connect to. #[arg(long, env, default_value = "wss://api.firezone.dev")] portal_ws_url: Url, @@ -134,7 +139,10 @@ async fn main() -> Result<()> { let mut eventloop = Eventloop::new(server, channel, args.listen_ip4_addr, &mut metric_registry).await?; - tokio::spawn(relay::metrics::serve(args.listen_ip4_addr, metric_registry)); + + if let Some(metrics_addr) = args.metrics_addr { + tokio::spawn(relay::metrics::serve(metrics_addr, metric_registry)); + } tracing::info!("Listening for incoming traffic on UDP port 3478"); diff --git a/rust/relay/src/metrics.rs b/rust/relay/src/metrics.rs index e9508776a..dbe96f6b3 100644 --- a/rust/relay/src/metrics.rs +++ b/rust/relay/src/metrics.rs @@ -5,15 +5,13 @@ use axum::response::IntoResponse; use axum::routing::get; use axum::{Router, Server}; use prometheus_client::registry::Registry; -use std::net::{IpAddr, SocketAddr}; +use std::net::SocketAddr; use std::sync::Arc; const CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;version=1.0.0"; -const PORT: u16 = 8080; -pub async fn serve(addr: impl Into, registry: Registry) -> Result<()> { +pub async fn serve(addr: impl Into, registry: Registry) -> Result<()> { let addr = addr.into(); - let addr = SocketAddr::new(addr, PORT); let service = Router::new() .route("/metrics", get(metrics))