sui_bridge_indexer/
metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use prometheus::{
5    IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Registry,
6    register_int_counter_vec_with_registry, register_int_counter_with_registry,
7    register_int_gauge_vec_with_registry, register_int_gauge_with_registry,
8};
9use sui_indexer_builder::metrics::IndexerMetricProvider;
10
11#[derive(Clone, Debug)]
12pub struct BridgeIndexerMetrics {
13    pub(crate) total_sui_bridge_transactions: IntCounter,
14    pub(crate) total_sui_token_deposited: IntCounter,
15    pub(crate) total_sui_token_transfer_approved: IntCounter,
16    pub(crate) total_sui_token_transfer_claimed: IntCounter,
17    pub(crate) total_sui_bridge_txn_other: IntCounter,
18    pub(crate) total_eth_bridge_transactions: IntCounter,
19    pub(crate) total_eth_token_deposited: IntCounter,
20    pub(crate) total_eth_token_transfer_claimed: IntCounter,
21    pub(crate) last_committed_sui_checkpoint: IntGauge,
22    pub(crate) backfill_tasks_remaining_checkpoints: IntGaugeVec,
23    pub(crate) tasks_processed_checkpoints: IntCounterVec,
24    pub(crate) tasks_latest_retrieved_checkpoints: IntGaugeVec,
25    pub(crate) inflight_live_tasks: IntGaugeVec,
26}
27
28impl BridgeIndexerMetrics {
29    pub fn new(registry: &Registry) -> Self {
30        Self {
31            total_sui_bridge_transactions: register_int_counter_with_registry!(
32                "bridge_indexer_total_sui_bridge_transactions",
33                "Total number of sui bridge transactions",
34                registry,
35            )
36            .unwrap(),
37            total_sui_token_deposited: register_int_counter_with_registry!(
38                "bridge_indexer_total_sui_token_deposited",
39                "Total number of sui token deposited transactions",
40                registry,
41            )
42            .unwrap(),
43            total_sui_token_transfer_approved: register_int_counter_with_registry!(
44                "bridge_indexer_total_sui_token_transfer_approved",
45                "Total number of sui token approved transactions",
46                registry,
47            )
48            .unwrap(),
49            total_sui_token_transfer_claimed: register_int_counter_with_registry!(
50                "bridge_indexer_total_sui_token_transfer_claimed",
51                "Total number of sui token claimed transactions",
52                registry,
53            )
54            .unwrap(),
55            total_sui_bridge_txn_other: register_int_counter_with_registry!(
56                "bridge_indexer_total_sui_bridge_txn_other",
57                "Total number of other sui bridge transactions",
58                registry,
59            )
60            .unwrap(),
61            total_eth_bridge_transactions: register_int_counter_with_registry!(
62                "bridge_indexer_total_eth_bridge_transactions",
63                "Total number of eth bridge transactions",
64                registry,
65            )
66            .unwrap(),
67            total_eth_token_deposited: register_int_counter_with_registry!(
68                "bridge_indexer_total_eth_token_deposited",
69                "Total number of eth token deposited transactions",
70                registry,
71            )
72            .unwrap(),
73            total_eth_token_transfer_claimed: register_int_counter_with_registry!(
74                "bridge_indexer_total_eth_token_transfer_claimed",
75                "Total number of eth token claimed transactions",
76                registry,
77            )
78            .unwrap(),
79            last_committed_sui_checkpoint: register_int_gauge_with_registry!(
80                "bridge_indexer_last_committed_sui_checkpoint",
81                "The latest sui checkpoint that indexer committed to DB",
82                registry,
83            )
84            .unwrap(),
85            backfill_tasks_remaining_checkpoints: register_int_gauge_vec_with_registry!(
86                "bridge_indexer_backfill_tasks_remaining_checkpoints",
87                "The remaining checkpoints for the currently running backfill task",
88                &["task_name"],
89                registry,
90            )
91            .unwrap(),
92            tasks_processed_checkpoints: register_int_counter_vec_with_registry!(
93                "bridge_indexer_tasks_processed_checkpoints",
94                "Total processed checkpoints for each task",
95                &["task_name", "task_type"],
96                registry,
97            )
98            .unwrap(),
99            tasks_latest_retrieved_checkpoints: register_int_gauge_vec_with_registry!(
100                "bridge_indexer_tasks_latest_retrieved_checkpoints",
101                "latest retrieved checkpoint for each task",
102                &["task_name", "task_type"],
103                registry,
104            )
105            .unwrap(),
106            inflight_live_tasks: register_int_gauge_vec_with_registry!(
107                "bridge_indexer_inflight_live_tasks",
108                "Number of inflight live tasks",
109                &["task_name"],
110                registry,
111            )
112            .unwrap(),
113        }
114    }
115
116    pub fn new_for_testing() -> Self {
117        let registry = Registry::new();
118        Self::new(&registry)
119    }
120}
121
122impl IndexerMetricProvider for BridgeIndexerMetrics {
123    fn get_tasks_latest_retrieved_checkpoints(&self) -> &IntGaugeVec {
124        &self.tasks_latest_retrieved_checkpoints
125    }
126
127    fn get_tasks_remaining_checkpoints_metric(&self) -> &IntGaugeVec {
128        &self.backfill_tasks_remaining_checkpoints
129    }
130
131    fn get_tasks_processed_checkpoints_metric(&self) -> &IntCounterVec {
132        &self.tasks_processed_checkpoints
133    }
134
135    fn get_inflight_live_tasks_metrics(&self) -> &IntGaugeVec {
136        &self.inflight_live_tasks
137    }
138}