sui_bridge_indexer/
metrics.rs1use prometheus::{
5 IntCounter, IntCounterVec, IntGaugeVec, Registry, register_int_counter_vec_with_registry,
6 register_int_counter_with_registry, register_int_gauge_vec_with_registry,
7};
8
9pub trait IndexerMetricProvider: Send + Sync {
10 fn get_tasks_latest_retrieved_checkpoints(&self) -> &IntGaugeVec;
11
12 fn get_tasks_remaining_checkpoints_metric(&self) -> &IntGaugeVec;
13
14 fn get_tasks_processed_checkpoints_metric(&self) -> &IntCounterVec;
15
16 fn get_inflight_live_tasks_metrics(&self) -> &IntGaugeVec;
17
18 fn boxed(self) -> Box<dyn IndexerMetricProvider>
19 where
20 Self: Sized + 'static,
21 {
22 Box::new(self)
23 }
24}
25
26#[derive(Clone, Debug)]
27pub struct BridgeIndexerMetrics {
28 pub(crate) total_eth_bridge_transactions: IntCounter,
29 pub(crate) total_eth_token_deposited: IntCounter,
30 pub(crate) total_eth_token_transfer_claimed: IntCounter,
31 pub(crate) backfill_tasks_remaining_checkpoints: IntGaugeVec,
32 pub(crate) tasks_processed_checkpoints: IntCounterVec,
33 pub(crate) tasks_latest_retrieved_checkpoints: IntGaugeVec,
34 pub(crate) inflight_live_tasks: IntGaugeVec,
35}
36
37impl BridgeIndexerMetrics {
38 pub fn new(registry: &Registry) -> Self {
39 Self {
40 total_eth_bridge_transactions: register_int_counter_with_registry!(
41 "bridge_indexer_total_eth_bridge_transactions",
42 "Total number of eth bridge transactions",
43 registry,
44 )
45 .unwrap(),
46 total_eth_token_deposited: register_int_counter_with_registry!(
47 "bridge_indexer_total_eth_token_deposited",
48 "Total number of eth token deposited transactions",
49 registry,
50 )
51 .unwrap(),
52 total_eth_token_transfer_claimed: register_int_counter_with_registry!(
53 "bridge_indexer_total_eth_token_transfer_claimed",
54 "Total number of eth token claimed transactions",
55 registry,
56 )
57 .unwrap(),
58 backfill_tasks_remaining_checkpoints: register_int_gauge_vec_with_registry!(
59 "bridge_indexer_backfill_tasks_remaining_checkpoints",
60 "The remaining checkpoints for the currently running backfill task",
61 &["task_name"],
62 registry,
63 )
64 .unwrap(),
65 tasks_processed_checkpoints: register_int_counter_vec_with_registry!(
66 "bridge_indexer_tasks_processed_checkpoints",
67 "Total processed checkpoints for each task",
68 &["task_name", "task_type"],
69 registry,
70 )
71 .unwrap(),
72 tasks_latest_retrieved_checkpoints: register_int_gauge_vec_with_registry!(
73 "bridge_indexer_tasks_latest_retrieved_checkpoints",
74 "latest retrieved checkpoint for each task",
75 &["task_name", "task_type"],
76 registry,
77 )
78 .unwrap(),
79 inflight_live_tasks: register_int_gauge_vec_with_registry!(
80 "bridge_indexer_inflight_live_tasks",
81 "Number of inflight live tasks",
82 &["task_name"],
83 registry,
84 )
85 .unwrap(),
86 }
87 }
88
89 pub fn new_for_testing() -> Self {
90 let registry = Registry::new();
91 Self::new(®istry)
92 }
93}
94
95impl IndexerMetricProvider for BridgeIndexerMetrics {
96 fn get_tasks_latest_retrieved_checkpoints(&self) -> &IntGaugeVec {
97 &self.tasks_latest_retrieved_checkpoints
98 }
99
100 fn get_tasks_remaining_checkpoints_metric(&self) -> &IntGaugeVec {
101 &self.backfill_tasks_remaining_checkpoints
102 }
103
104 fn get_tasks_processed_checkpoints_metric(&self) -> &IntCounterVec {
105 &self.tasks_processed_checkpoints
106 }
107
108 fn get_inflight_live_tasks_metrics(&self) -> &IntGaugeVec {
109 &self.inflight_live_tasks
110 }
111}