diff --git a/apps/fortuna/src/keeper.rs b/apps/fortuna/src/keeper.rs index 2387145a..12cc860a 100644 --- a/apps/fortuna/src/keeper.rs +++ b/apps/fortuna/src/keeper.rs @@ -238,6 +238,18 @@ pub async fn process_event( "Revealed with res: {:?}", res ); + + if let Some(gas_used) = res.gas_used { + let gas_used = gas_used.as_u128() as f64 / 1e18; + metrics + .total_gas_spent + .get_or_create(&ProviderLabel { + chain_id: chain_config.id.clone(), + address: chain_config.provider_address.to_string(), + }) + .inc_by(gas_used); + } + metrics .reveals .get_or_create(&ProviderLabel { diff --git a/apps/fortuna/src/metrics.rs b/apps/fortuna/src/metrics.rs index 20ed1715..08da973b 100644 --- a/apps/fortuna/src/metrics.rs +++ b/apps/fortuna/src/metrics.rs @@ -39,14 +39,10 @@ pub struct Metrics { pub end_sequence_number: Family, pub balance: Family>, pub collected_fee: Family>, - // + pub total_gas_spent: Family>, pub requests: Family, pub requests_processed: Family, pub reveals: Family, - // NOTE: gas_spending is not part of metrics. - // why? - // - it is not a value that increases or decreases over time. Not a counter or a gauge - // - it can't fit in a histogram too. logging and then collecting it is better. // NOTE: rpc is not part of metrics. // why? // - which metric type should we use to track it? @@ -129,6 +125,15 @@ impl Metrics { collected_fee.clone(), ); + let total_gas_spent = Family::>::default(); + metrics_registry.register( + // With the metric name. + "total_gas_spent", + // And the metric help text. + "Total gas spent revealing requests", + total_gas_spent.clone(), + ); + Metrics { registry: RwLock::new(metrics_registry), request_counter: http_requests, @@ -139,6 +144,7 @@ impl Metrics { reveals, balance, collected_fee, + total_gas_spent, } } }