Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions apps/fortuna/src/keeper/keeper_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct KeeperMetrics {
pub final_gas_multiplier: Family<AccountLabel, Histogram>,
pub final_fee_multiplier: Family<AccountLabel, Histogram>,
pub gas_price_estimate: Family<AccountLabel, Gauge<f64, AtomicU64>>,
pub accrued_pyth_fees: Family<AccountLabel, Gauge<f64, AtomicU64>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the key for this Family should be chain id not AccountLabel

}

impl Default for KeeperMetrics {
Expand Down Expand Up @@ -76,6 +77,7 @@ impl Default for KeeperMetrics {
Histogram::new(vec![100.0, 110.0, 120.0, 140.0, 160.0, 180.0, 200.0].into_iter())
}),
gas_price_estimate: Family::default(),
accrued_pyth_fees: Family::default(),
}
}
}
Expand Down Expand Up @@ -202,6 +204,12 @@ impl KeeperMetrics {
keeper_metrics.gas_price_estimate.clone(),
);

writable_registry.register(
"accrued_pyth_fees",
"Accrued Pyth fees on the contract",
keeper_metrics.accrued_pyth_fees.clone(),
);

// *Important*: When adding a new metric:
// 1. Register it above using `writable_registry.register(...)`
// 2. Add a get_or_create call in the loop below to initialize it for each chain/provider pair
Expand Down Expand Up @@ -254,6 +262,9 @@ impl KeeperMetrics {
let _ = keeper_metrics
.gas_price_estimate
.get_or_create(&account_label);
let _ = keeper_metrics
.accrued_pyth_fees
.get_or_create(&account_label);
}

keeper_metrics
Expand Down
29 changes: 29 additions & 0 deletions apps/fortuna/src/keeper/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,32 @@ pub async fn track_provider(
})
.set(end_sequence_number as i64);
}

/// tracks the accrued pyth fees on the given chain
/// if there is an error the function will just return
#[tracing::instrument(skip_all)]
pub async fn track_accrued_pyth_fees(
chain_id: ChainId,
contract: InstrumentedPythContract,
metrics: Arc<KeeperMetrics>,
) {
let accrued_pyth_fees = match contract.get_accrued_pyth_fees().call().await {
Ok(fees) => fees,
Err(e) => {
tracing::error!("Error while getting accrued pyth fees. error: {:?}", e);
return;
}
};

// The f64 conversion is made to be able to serve metrics with the constraints of Prometheus.
// The fee is in wei, so we divide by 1e18 to convert it to eth.
let accrued_pyth_fees = accrued_pyth_fees as f64 / 1e18;

metrics
.accrued_pyth_fees
.get_or_create(&AccountLabel {
chain_id: chain_id.clone(),
address: "global".to_string(),
})
.set(accrued_pyth_fees);
}
Loading