From 444b181275eb9855c2996e29e59d69199b8ff86e Mon Sep 17 00:00:00 2001 From: Asmir Avdicevic Date: Wed, 15 May 2024 12:01:10 +0200 Subject: [PATCH 1/2] feat(cli): add metrics server to iroh doctor --- iroh-cli/src/commands/doctor.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/iroh-cli/src/commands/doctor.rs b/iroh-cli/src/commands/doctor.rs index 01445e2d33..156bb4dd9d 100644 --- a/iroh-cli/src/commands/doctor.rs +++ b/iroh-cli/src/commands/doctor.rs @@ -1068,7 +1068,8 @@ fn inspect_ticket(ticket: &str, zbase32: bool) -> anyhow::Result<()> { pub async fn run(command: Commands, config: &NodeConfig) -> anyhow::Result<()> { let data_dir = iroh_data_root()?; let _guard = crate::logging::init_terminal_and_file_logging(&config.file_logs, &data_dir)?; - match command { + let metrics_fut = super::start::start_metrics_server(config.metrics_addr); + let cmd_res = match command { Commands::Report { stun_host, stun_port, @@ -1200,7 +1201,11 @@ pub async fn run(command: Commands, config: &NodeConfig) -> anyhow::Result<()> { Ok(()) } + }; + if let Some(metrics_fut) = metrics_fut { + metrics_fut.abort(); } + cmd_res } async fn run_plotter( From b125d0884d5727507feebb5d01d03abde5e7779a Mon Sep 17 00:00:00 2001 From: Asmir Avdicevic Date: Wed, 22 May 2024 22:23:17 +0200 Subject: [PATCH 2/2] default off metrics --- iroh-cli/src/commands.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/iroh-cli/src/commands.rs b/iroh-cli/src/commands.rs index 9fd279be12..2e53bd3e0e 100644 --- a/iroh-cli/src/commands.rs +++ b/iroh-cli/src/commands.rs @@ -37,7 +37,7 @@ pub(crate) struct Cli { #[clap(long, global = true)] start: bool, - /// Port to serve metrics on. -1 to disable. + /// Port to serve metrics on. Disabled by default. #[clap(long)] pub(crate) metrics_port: Option, } @@ -184,7 +184,13 @@ impl Cli { .await } Commands::Doctor { command } => { - let config = NodeConfig::load(self.config.as_deref()).await?; + let mut config = NodeConfig::load(self.config.as_deref()).await?; + if let Some(metrics_port) = self.metrics_port { + config.metrics_addr = match metrics_port { + MetricsPort::Disabled => None, + MetricsPort::Port(port) => Some(([127, 0, 0, 1], port).into()), + }; + } self::doctor::run(command, &config).await } }