iota_bridge_indexer/
metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use prometheus::{
6    IntCounter, IntGauge, Registry, register_int_counter_with_registry,
7    register_int_gauge_with_registry,
8};
9
10#[derive(Clone, Debug)]
11pub struct BridgeIndexerMetrics {
12    pub(crate) total_iota_bridge_transactions: IntCounter,
13    pub(crate) total_iota_token_deposited: IntCounter,
14    pub(crate) total_iota_token_transfer_approved: IntCounter,
15    pub(crate) total_iota_token_transfer_claimed: IntCounter,
16    pub(crate) total_iota_bridge_txn_other: IntCounter,
17    pub(crate) total_eth_bridge_transactions: IntCounter,
18    pub(crate) total_eth_token_deposited: IntCounter,
19    pub(crate) total_eth_token_transfer_claimed: IntCounter,
20    pub(crate) total_eth_bridge_txn_other: IntCounter,
21    pub(crate) last_committed_iota_checkpoint: IntGauge,
22    pub(crate) latest_committed_eth_block: IntGauge,
23    pub(crate) last_synced_eth_block: IntGauge,
24}
25
26impl BridgeIndexerMetrics {
27    pub fn new(registry: &Registry) -> Self {
28        Self {
29            total_iota_bridge_transactions: register_int_counter_with_registry!(
30                "total_iota_bridge_transactions",
31                "Total number of iota bridge transactions",
32                registry,
33            )
34            .unwrap(),
35            total_iota_token_deposited: register_int_counter_with_registry!(
36                "total_iota_token_deposited",
37                "Total number of iota token deposited transactions",
38                registry,
39            )
40            .unwrap(),
41            total_iota_token_transfer_approved: register_int_counter_with_registry!(
42                "total_iota_token_transfer_approved",
43                "Total number of iota token approved transactions",
44                registry,
45            )
46            .unwrap(),
47            total_iota_token_transfer_claimed: register_int_counter_with_registry!(
48                "total_iota_token_transfer_claimed",
49                "Total number of iota token claimed transactions",
50                registry,
51            )
52            .unwrap(),
53            total_iota_bridge_txn_other: register_int_counter_with_registry!(
54                "total_iota_bridge_txn_other",
55                "Total number of other iota bridge transactions",
56                registry,
57            )
58            .unwrap(),
59            total_eth_bridge_transactions: register_int_counter_with_registry!(
60                "total_eth_bridge_transactions",
61                "Total number of eth bridge transactions",
62                registry,
63            )
64            .unwrap(),
65            total_eth_token_deposited: register_int_counter_with_registry!(
66                "total_eth_token_deposited",
67                "Total number of eth token deposited transactions",
68                registry,
69            )
70            .unwrap(),
71            total_eth_token_transfer_claimed: register_int_counter_with_registry!(
72                "total_eth_token_transfer_claimed",
73                "Total number of eth token claimed transactions",
74                registry,
75            )
76            .unwrap(),
77            total_eth_bridge_txn_other: register_int_counter_with_registry!(
78                "total_eth_bridge_txn_other",
79                "Total number of other eth bridge transactions",
80                registry,
81            )
82            .unwrap(),
83            last_committed_iota_checkpoint: register_int_gauge_with_registry!(
84                "last_committed_iota_checkpoint",
85                "The latest iota checkpoint that indexer committed to DB",
86                registry,
87            )
88            .unwrap(),
89            latest_committed_eth_block: register_int_gauge_with_registry!(
90                "last_committed_eth_block",
91                "The latest eth block that indexer committed to DB",
92                registry,
93            )
94            .unwrap(),
95            last_synced_eth_block: register_int_gauge_with_registry!(
96                "last_synced_eth_block",
97                "The last eth block that indexer committed to DB",
98                registry,
99            )
100            .unwrap(),
101        }
102    }
103
104    pub fn new_for_testing() -> Self {
105        let registry = Registry::new();
106        Self::new(&registry)
107    }
108}