From 7ce62ba672597c4bfe2ff0994f2a8f810369bbb8 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Mon, 11 Dec 2023 11:13:30 +0100 Subject: [PATCH] Metrics for gas --- src/tasks/index.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/tasks/index.rs b/src/tasks/index.rs index fe430b2..0483938 100644 --- a/src/tasks/index.rs +++ b/src/tasks/index.rs @@ -17,6 +17,8 @@ const BLOCK_FEE_HISTORY_SIZE: usize = 10; const FEE_PERCENTILES: [f64; 5] = [5.0, 25.0, 50.0, 75.0, 95.0]; const TIME_BETWEEN_FEE_ESTIMATION_SECONDS: u64 = 30; +const GAS_PRICE_FOR_METRICS_FACTOR: f64 = 1e-9; + pub async fn index_chain(app: Arc, chain_id: u64) -> eyre::Result<()> { loop { let ws_rpc = app.ws_provider(chain_id).await?; @@ -107,6 +109,32 @@ pub async fn estimate_gas(app: Arc, chain_id: u64) -> eyre::Result<()> { ) .await?; + let labels = [("chain_id", chain_id.to_string())]; + metrics::gauge!( + "gas_price", + gas_price.as_u64() as f64 * GAS_PRICE_FOR_METRICS_FACTOR, + &labels + ); + metrics::gauge!( + "base_fee_per_gas", + fee_estimates.base_fee_per_gas.as_u64() as f64 + * GAS_PRICE_FOR_METRICS_FACTOR, + &labels + ); + + for (i, percentile) in FEE_PERCENTILES.iter().enumerate() { + let percentile_fee = fee_estimates.percentile_fees[i]; + + metrics::gauge!( + "percentile_fee", + percentile_fee.as_u64() as f64 * GAS_PRICE_FOR_METRICS_FACTOR, + &[ + ("chain_id", chain_id.to_string()), + ("percentile", percentile.to_string()), + ] + ); + } + tokio::time::sleep(Duration::from_secs( TIME_BETWEEN_FEE_ESTIMATION_SECONDS, ))