diff --git a/Cargo.lock b/Cargo.lock index 3386518162..91d29cfbf6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3579,6 +3579,7 @@ dependencies = [ "hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "portpicker 0.1.0 (git+https://github.com/wusyong/portpicker-rs?branch=fix_ipv6)", "prometheus 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "prometheus-static-metric 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/server/Cargo.toml b/server/Cargo.toml index a18d3eaffb..f972a05e65 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -24,3 +24,4 @@ crossbeam = "0.7.2" prometheus = "0.7" prometheus-static-metric = "0.2" rouille = "3.0.0" +portpicker = { git = "https://github.com/wusyong/portpicker-rs", branch = "fix_ipv6" } \ No newline at end of file diff --git a/server/src/metrics.rs b/server/src/metrics.rs index fb23a3aeb5..ec0ea388b1 100644 --- a/server/src/metrics.rs +++ b/server/src/metrics.rs @@ -1,3 +1,5 @@ +use log::info; +use portpicker::pick_unused_port; use prometheus::{Encoder, Gauge, IntGauge, IntGaugeVec, Opts, Registry, TextEncoder}; use rouille::{router, Server}; use std::{ @@ -93,7 +95,10 @@ impl ServerMetrics { //TODO: make this a job let handle = Some(thread::spawn(move || { - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 14005); + let addr = SocketAddr::new( + IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), + pick_unused_port().expect("Failed to find unused port!"), + ); let server = Server::new(addr, move |request| { router!(request, (GET) (/metrics) => { @@ -107,6 +112,7 @@ impl ServerMetrics { ) }) .expect("Failed to start server"); + info!("Started server metrics: {}", addr); while running2.load(Ordering::Relaxed) { server.poll(); // Poll at 10Hz