1use prometheus::{
6 HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Registry,
7 register_histogram_vec_with_registry, register_int_counter_vec_with_registry,
8 register_int_counter_with_registry, register_int_gauge_vec_with_registry,
9 register_int_gauge_with_registry,
10};
11
12const FINE_GRAINED_LATENCY_SEC_BUCKETS: &[f64] = &[
13 0.001, 0.005, 0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9,
14 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.0, 3.5, 4.0, 5.0, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5,
15 10., 15., 20., 25., 30., 35., 40., 45., 50., 60., 70., 80., 90., 100., 120., 140., 160., 180.,
16 200., 250., 300., 350., 400.,
17];
18
19#[derive(Clone, Debug)]
20pub struct BridgeMetrics {
21 pub(crate) err_build_iota_transaction: IntCounter,
22 pub(crate) err_signature_aggregation: IntCounter,
23 pub(crate) err_iota_transaction_submission: IntCounter,
24 pub(crate) err_iota_transaction_submission_too_many_failures: IntCounter,
25 pub(crate) err_iota_transaction_execution: IntCounter,
26 pub(crate) requests_received: IntCounterVec,
27 pub(crate) requests_ok: IntCounterVec,
28 pub(crate) err_requests: IntCounterVec,
29 pub(crate) requests_inflight: IntGaugeVec,
30
31 pub last_synced_iota_checkpoint: IntGauge,
32 pub(crate) last_finalized_eth_block: IntGauge,
33 pub(crate) last_synced_eth_block: IntGauge,
34
35 pub(crate) iota_watcher_received_events: IntCounter,
36 pub(crate) iota_watcher_received_actions: IntCounter,
37 pub(crate) iota_watcher_unrecognized_events: IntCounter,
38 pub(crate) eth_watcher_received_events: IntCounter,
39 pub(crate) eth_watcher_received_actions: IntCounter,
40 pub(crate) eth_watcher_unrecognized_events: IntCounter,
41 pub(crate) action_executor_already_processed_actions: IntCounter,
42 pub(crate) action_executor_signing_queue_received_actions: IntCounter,
43 pub(crate) action_executor_signing_queue_skipped_actions: IntCounter,
44 pub(crate) action_executor_execution_queue_received_actions: IntCounter,
45 pub(crate) action_executor_execution_queue_skipped_actions_due_to_pausing: IntCounter,
46
47 pub(crate) signer_with_cache_hit: IntCounterVec,
48 pub(crate) signer_with_cache_miss: IntCounterVec,
49
50 pub(crate) eth_rpc_queries: IntCounterVec,
51 pub(crate) eth_rpc_queries_latency: HistogramVec,
52
53 pub(crate) gas_coin_balance: IntGauge,
54}
55
56impl BridgeMetrics {
57 pub fn new(registry: &Registry) -> Self {
58 Self {
59 err_build_iota_transaction: register_int_counter_with_registry!(
60 "bridge_err_build_iota_transaction",
61 "Total number of errors of building iota transactions",
62 registry,
63 )
64 .unwrap(),
65 err_signature_aggregation: register_int_counter_with_registry!(
66 "bridge_err_signature_aggregation",
67 "Total number of errors of aggregating validators signatures",
68 registry,
69 )
70 .unwrap(),
71 err_iota_transaction_submission: register_int_counter_with_registry!(
72 "bridge_err_iota_transaction_submission",
73 "Total number of errors of submitting iota transactions",
74 registry,
75 )
76 .unwrap(),
77 err_iota_transaction_submission_too_many_failures: register_int_counter_with_registry!(
78 "bridge_err_iota_transaction_submission_too_many_failures",
79 "Total number of continuous failures to submitting iota transactions",
80 registry,
81 )
82 .unwrap(),
83 err_iota_transaction_execution: register_int_counter_with_registry!(
84 "bridge_err_iota_transaction_execution",
85 "Total number of failures of iota transaction execution",
86 registry,
87 )
88 .unwrap(),
89 requests_received: register_int_counter_vec_with_registry!(
90 "bridge_requests_received",
91 "Total number of requests received in Server, by request type",
92 &["type"],
93 registry,
94 )
95 .unwrap(),
96 requests_ok: register_int_counter_vec_with_registry!(
97 "bridge_requests_ok",
98 "Total number of ok requests, by request type",
99 &["type"],
100 registry,
101 )
102 .unwrap(),
103 err_requests: register_int_counter_vec_with_registry!(
104 "bridge_err_requests",
105 "Total number of erred requests, by request type",
106 &["type"],
107 registry,
108 )
109 .unwrap(),
110 requests_inflight: register_int_gauge_vec_with_registry!(
111 "bridge_requests_inflight",
112 "Total number of inflight requests, by request type",
113 &["type"],
114 registry,
115 )
116 .unwrap(),
117 iota_watcher_received_events: register_int_counter_with_registry!(
118 "bridge_iota_watcher_received_events",
119 "Total number of received events in iota watcher",
120 registry,
121 )
122 .unwrap(),
123 eth_watcher_received_events: register_int_counter_with_registry!(
124 "bridge_eth_watcher_received_events",
125 "Total number of received events in eth watcher",
126 registry,
127 )
128 .unwrap(),
129 iota_watcher_received_actions: register_int_counter_with_registry!(
130 "bridge_iota_watcher_received_actions",
131 "Total number of received actions in iota watcher",
132 registry,
133 )
134 .unwrap(),
135 eth_watcher_received_actions: register_int_counter_with_registry!(
136 "bridge_eth_watcher_received_actions",
137 "Total number of received actions in eth watcher",
138 registry,
139 )
140 .unwrap(),
141 iota_watcher_unrecognized_events: register_int_counter_with_registry!(
142 "bridge_iota_watcher_unrecognized_events",
143 "Total number of unrecognized events in iota watcher",
144 registry,
145 )
146 .unwrap(),
147 eth_watcher_unrecognized_events: register_int_counter_with_registry!(
148 "bridge_eth_watcher_unrecognized_events",
149 "Total number of unrecognized events in eth watcher",
150 registry,
151 )
152 .unwrap(),
153 action_executor_already_processed_actions: register_int_counter_with_registry!(
154 "bridge_action_executor_already_processed_actions",
155 "Total number of already processed actions action executor",
156 registry,
157 )
158 .unwrap(),
159 action_executor_signing_queue_received_actions: register_int_counter_with_registry!(
160 "bridge_action_executor_signing_queue_received_actions",
161 "Total number of received actions in action executor signing queue",
162 registry,
163 )
164 .unwrap(),
165 action_executor_signing_queue_skipped_actions: register_int_counter_with_registry!(
166 "bridge_action_executor_signing_queue_skipped_actions",
167 "Total number of skipped actions in action executor signing queue",
168 registry,
169 )
170 .unwrap(),
171 action_executor_execution_queue_received_actions: register_int_counter_with_registry!(
172 "bridge_action_executor_execution_queue_received_actions",
173 "Total number of received actions in action executor execution queue",
174 registry,
175 )
176 .unwrap(),
177 action_executor_execution_queue_skipped_actions_due_to_pausing: register_int_counter_with_registry!(
178 "bridge_action_executor_execution_queue_skipped_actions_due_to_pausing",
179 "Total number of skipped actions in action executor execution queue because of pausing",
180 registry,
181 )
182 .unwrap(),
183 gas_coin_balance: register_int_gauge_with_registry!(
184 "bridge_gas_coin_balance",
185 "Current balance of gas coin, in nanos",
186 registry,
187 )
188 .unwrap(),
189 eth_rpc_queries: register_int_counter_vec_with_registry!(
190 "bridge_eth_rpc_queries",
191 "Total number of queries issued to eth provider, by request type",
192 &["type"],
193 registry,
194 )
195 .unwrap(),
196 eth_rpc_queries_latency: register_histogram_vec_with_registry!(
197 "bridge_eth_rpc_queries_latency",
198 "Latency of queries issued to eth provider, by request type",
199 &["type"],
200 FINE_GRAINED_LATENCY_SEC_BUCKETS.to_vec(),
201 registry,
202 )
203 .unwrap(),
204 last_synced_iota_checkpoint: register_int_gauge_with_registry!(
205 "last_synced_iota_checkpoint",
206 "The latest iota checkpoint that indexer synced",
207 registry,
208 )
209 .unwrap(),
210 last_synced_eth_block: register_int_gauge_with_registry!(
211 "bridge_last_synced_eth_block",
212 "The latest finalized eth block that indexer synced",
213 registry,
214 )
215 .unwrap(),
216 last_finalized_eth_block: register_int_gauge_with_registry!(
217 "bridge_last_finalized_eth_block",
218 "The latest finalized eth block that indexer observed",
219 registry,
220 )
221 .unwrap(),
222 signer_with_cache_hit: register_int_counter_vec_with_registry!(
223 "bridge_signer_with_cache_hit",
224 "Total number of hit in signer's cache, by verifier type",
225 &["type"],
226 registry,
227 )
228 .unwrap(),
229 signer_with_cache_miss: register_int_counter_vec_with_registry!(
230 "bridge_signer_with_cache_miss",
231 "Total number of miss in signer's cache, by verifier type",
232 &["type"],
233 registry,
234 )
235 .unwrap(),
236 }
237 }
238
239 pub fn new_for_testing() -> Self {
240 let registry = Registry::new();
241 Self::new(®istry)
242 }
243}