diff --git a/crates/blockchain/metrics/metrics_blocks.rs b/crates/blockchain/metrics/metrics_blocks.rs index 2dead6b1925..4b8f00aa736 100644 --- a/crates/blockchain/metrics/metrics_blocks.rs +++ b/crates/blockchain/metrics/metrics_blocks.rs @@ -10,6 +10,9 @@ pub struct MetricsBlocks { gas_limit: Gauge, block_number: IntGauge, gigagas: Gauge, + gigagas_block_building: Gauge, + block_building_ms: IntGauge, + block_building_base_fee: IntGauge, gas_used: Gauge, } @@ -34,9 +37,24 @@ impl MetricsBlocks { .unwrap(), gigagas: Gauge::new( "gigagas", + "Keeps track of the block execution throughput through gigagas/s", + ) + .unwrap(), + gigagas_block_building: Gauge::new( + "gigagas_block_building", "Keeps track of the block building throughput through gigagas/s", ) .unwrap(), + block_building_ms: IntGauge::new( + "block_building_ms", + "Keeps track of the block building throughput through miliseconds", + ) + .unwrap(), + block_building_base_fee: IntGauge::new( + "block_building_base_fee", + "Keeps track of the block building base fee", + ) + .unwrap(), gas_used: Gauge::new( "gas_used", "Keeps track of the gas used in the latest block", @@ -53,6 +71,18 @@ impl MetricsBlocks { self.gigagas.set(gigagas); } + pub fn set_latest_gigagas_block_building(&self, gigagas: f64) { + self.gigagas_block_building.set(gigagas); + } + + pub fn set_block_building_ms(&self, ms: i64) { + self.block_building_ms.set(ms); + } + + pub fn set_block_building_base_fee(&self, base_fee: i64) { + self.block_building_base_fee.set(base_fee); + } + pub fn set_block_number(&self, block_number: u64) -> Result<(), MetricsError> { self.block_number.set(block_number.try_into()?); Ok(()) diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 280854e90c9..d3842787b0e 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -27,6 +27,8 @@ use sha3::{Digest, Keccak256}; use ethrex_metrics::metrics; +#[cfg(feature = "metrics")] +use ethrex_metrics::metrics_blocks::METRICS_BLOCKS; #[cfg(feature = "metrics")] use ethrex_metrics::metrics_transactions::{METRICS_TX, MetricsTxType}; use tokio_util::sync::CancellationToken; @@ -401,21 +403,20 @@ impl Blockchain { self.finalize_payload(&mut context).await?; let interval = Instant::now().duration_since(since).as_millis(); - // TODO: expose as a proper metric - // Commented out because we build multiple blocks per request - // each one printing this metric can be spammy + tracing::debug!( "[METRIC] BUILDING PAYLOAD TOOK: {interval} ms, base fee {}", base_fee ); + metrics!(METRICS_BLOCKS.set_block_building_ms(interval as i64)); + metrics!(METRICS_BLOCKS.set_block_building_base_fee(base_fee as i64)); if let Some(gas_used) = gas_limit.checked_sub(context.remaining_gas) { let as_gigas = (gas_used as f64).div(10_f64.powf(9_f64)); if interval != 0 { let throughput = (as_gigas) / (interval as f64) * 1000_f64; - // TODO: expose as a proper metric - // Commented out because we build multiple blocks per request - // each one printing this metric can be spammy + metrics!(METRICS_BLOCKS.set_latest_gigagas_block_building(throughput)); + tracing::debug!( "[METRIC] BLOCK BUILDING THROUGHPUT: {throughput} Gigagas/s TIME SPENT: {interval} msecs" );