From 0470c65e6c78918b15112b2ed7f2b2918c4f02a9 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 30 Jan 2026 03:24:25 +0000 Subject: [PATCH] feat(cli): add --metrics param to `reth prune` (#21613) Co-authored-by: Georgios Konstantopoulos Co-authored-by: Amp --- crates/cli/commands/src/prune.rs | 40 ++++++++++++++++++++-- crates/ethereum/cli/src/app.rs | 2 +- crates/optimism/cli/src/app.rs | 4 ++- docs/vocs/docs/pages/cli/op-reth/prune.mdx | 18 ++++++++++ docs/vocs/docs/pages/cli/reth/prune.mdx | 18 ++++++++++ 5 files changed, 78 insertions(+), 4 deletions(-) diff --git a/crates/cli/commands/src/prune.rs b/crates/cli/commands/src/prune.rs index cae0fa0090..b9085e7a8a 100644 --- a/crates/cli/commands/src/prune.rs +++ b/crates/cli/commands/src/prune.rs @@ -1,8 +1,16 @@ //! Command that runs pruning without any limits. use crate::common::{AccessRights, CliNodeTypes, EnvironmentArgs}; use clap::Parser; -use reth_chainspec::{EthChainSpec, EthereumHardforks}; +use reth_chainspec::{ChainSpecProvider, EthChainSpec, EthereumHardforks}; use reth_cli::chainspec::ChainSpecParser; +use reth_cli_runner::CliContext; +use reth_node_builder::common::metrics_hooks; +use reth_node_core::{args::MetricArgs, version::version_metadata}; +use reth_node_metrics::{ + chain::ChainSpecInfo, + server::{MetricServer, MetricServerConfig}, + version::VersionInfo, +}; use reth_prune::PrunerBuilder; use reth_static_file::StaticFileProducer; use std::sync::Arc; @@ -13,14 +21,42 @@ use tracing::info; pub struct PruneCommand { #[command(flatten)] env: EnvironmentArgs, + + /// Prometheus metrics configuration. + #[command(flatten)] + metrics: MetricArgs, } impl> PruneCommand { /// Execute the `prune` command - pub async fn execute>(self) -> eyre::Result<()> { + pub async fn execute>( + self, + ctx: CliContext, + ) -> eyre::Result<()> { let env = self.env.init::(AccessRights::RW)?; let provider_factory = env.provider_factory; let config = env.config.prune; + let data_dir = env.data_dir; + + if let Some(listen_addr) = self.metrics.prometheus { + let config = MetricServerConfig::new( + listen_addr, + VersionInfo { + version: version_metadata().cargo_pkg_version.as_ref(), + build_timestamp: version_metadata().vergen_build_timestamp.as_ref(), + cargo_features: version_metadata().vergen_cargo_features.as_ref(), + git_sha: version_metadata().vergen_git_sha.as_ref(), + target_triple: version_metadata().vergen_cargo_target_triple.as_ref(), + build_profile: version_metadata().build_profile_name.as_ref(), + }, + ChainSpecInfo { name: provider_factory.chain_spec().chain().to_string() }, + ctx.task_executor, + metrics_hooks(&provider_factory), + data_dir.pprof_dumps(), + ); + + MetricServer::new(config).serve().await?; + } // Copy data from database to static files info!(target: "reth::cli", "Copying data from database to static files..."); diff --git a/crates/ethereum/cli/src/app.rs b/crates/ethereum/cli/src/app.rs index 50a7bf64d7..33f272d097 100644 --- a/crates/ethereum/cli/src/app.rs +++ b/crates/ethereum/cli/src/app.rs @@ -174,7 +174,7 @@ where } Commands::P2P(command) => runner.run_until_ctrl_c(command.execute::()), Commands::Config(command) => runner.run_until_ctrl_c(command.execute()), - Commands::Prune(command) => runner.run_until_ctrl_c(command.execute::()), + Commands::Prune(command) => runner.run_command_until_exit(|ctx| command.execute::(ctx)), #[cfg(feature = "dev")] Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()), Commands::ReExecute(command) => runner.run_until_ctrl_c(command.execute::(components)), diff --git a/crates/optimism/cli/src/app.rs b/crates/optimism/cli/src/app.rs index 4dbdd81057..2ef171a473 100644 --- a/crates/optimism/cli/src/app.rs +++ b/crates/optimism/cli/src/app.rs @@ -106,7 +106,9 @@ where } Commands::P2P(command) => runner.run_until_ctrl_c(command.execute::()), Commands::Config(command) => runner.run_until_ctrl_c(command.execute()), - Commands::Prune(command) => runner.run_until_ctrl_c(command.execute::()), + Commands::Prune(command) => { + runner.run_command_until_exit(|ctx| command.execute::(ctx)) + } #[cfg(feature = "dev")] Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()), Commands::ReExecute(command) => { diff --git a/docs/vocs/docs/pages/cli/op-reth/prune.mdx b/docs/vocs/docs/pages/cli/op-reth/prune.mdx index c858c19303..a033f6d71c 100644 --- a/docs/vocs/docs/pages/cli/op-reth/prune.mdx +++ b/docs/vocs/docs/pages/cli/op-reth/prune.mdx @@ -181,6 +181,24 @@ RocksDB: [default: false] [possible values: true, false] +Metrics: + --metrics + Enable Prometheus metrics. + + The metrics will be served at the given interface and port. + + --metrics.prometheus.push.url + URL for pushing Prometheus metrics to a push gateway. + + If set, the node will periodically push metrics to the specified push gateway URL. + + --metrics.prometheus.push.interval + Interval in seconds for pushing metrics to push gateway. + + Default: 5 seconds + + [default: 5] + Logging: --log.stdout.format The format to use for logs written to stdout diff --git a/docs/vocs/docs/pages/cli/reth/prune.mdx b/docs/vocs/docs/pages/cli/reth/prune.mdx index fef01ec44a..53c6de0f04 100644 --- a/docs/vocs/docs/pages/cli/reth/prune.mdx +++ b/docs/vocs/docs/pages/cli/reth/prune.mdx @@ -181,6 +181,24 @@ RocksDB: [default: false] [possible values: true, false] +Metrics: + --metrics + Enable Prometheus metrics. + + The metrics will be served at the given interface and port. + + --metrics.prometheus.push.url + URL for pushing Prometheus metrics to a push gateway. + + If set, the node will periodically push metrics to the specified push gateway URL. + + --metrics.prometheus.push.interval + Interval in seconds for pushing metrics to push gateway. + + Default: 5 seconds + + [default: 5] + Logging: --log.stdout.format The format to use for logs written to stdout