Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add metrics server to iroh doctor #2292

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions iroh-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetricsPort>,
}
Expand Down Expand Up @@ -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
}
}
Expand Down
7 changes: 6 additions & 1 deletion iroh-cli/src/commands/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<B: Backend>(
Expand Down
Loading