Skip to content

Commit d635d93

Browse files
authored
feat(cli): add metrics server to iroh doctor (#2292)
## Description Folks try to look at metrics while doctor alone is running (note this clashes by default with the iroh node if both are running locally on port :9090). Also kind of inconvenient given if you want to look at a running iroh node when doctor is running. Suggestions welcome, maybe default off metrics on `doctor`? Also most metrics are not really used in the `doctor` path, but we can fix that as we figure out what's cool to measure. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [x] Self-review. - [ ] Documentation updates if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented.
1 parent 98d45f3 commit d635d93

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

iroh-cli/src/commands.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(crate) struct Cli {
3737
#[clap(long, global = true)]
3838
start: bool,
3939

40-
/// Port to serve metrics on. -1 to disable.
40+
/// Port to serve metrics on. Disabled by default.
4141
#[clap(long)]
4242
pub(crate) metrics_port: Option<MetricsPort>,
4343
}
@@ -184,7 +184,13 @@ impl Cli {
184184
.await
185185
}
186186
Commands::Doctor { command } => {
187-
let config = NodeConfig::load(self.config.as_deref()).await?;
187+
let mut config = NodeConfig::load(self.config.as_deref()).await?;
188+
if let Some(metrics_port) = self.metrics_port {
189+
config.metrics_addr = match metrics_port {
190+
MetricsPort::Disabled => None,
191+
MetricsPort::Port(port) => Some(([127, 0, 0, 1], port).into()),
192+
};
193+
}
188194
self::doctor::run(command, &config).await
189195
}
190196
}

iroh-cli/src/commands/doctor.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,8 @@ fn inspect_ticket(ticket: &str, zbase32: bool) -> anyhow::Result<()> {
10681068
pub async fn run(command: Commands, config: &NodeConfig) -> anyhow::Result<()> {
10691069
let data_dir = iroh_data_root()?;
10701070
let _guard = crate::logging::init_terminal_and_file_logging(&config.file_logs, &data_dir)?;
1071-
match command {
1071+
let metrics_fut = super::start::start_metrics_server(config.metrics_addr);
1072+
let cmd_res = match command {
10721073
Commands::Report {
10731074
stun_host,
10741075
stun_port,
@@ -1200,7 +1201,11 @@ pub async fn run(command: Commands, config: &NodeConfig) -> anyhow::Result<()> {
12001201

12011202
Ok(())
12021203
}
1204+
};
1205+
if let Some(metrics_fut) = metrics_fut {
1206+
metrics_fut.abort();
12031207
}
1208+
cmd_res
12041209
}
12051210

12061211
async fn run_plotter<B: Backend>(

0 commit comments

Comments
 (0)