-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmetrics.rs
53 lines (47 loc) · 1.53 KB
/
metrics.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use once_cell::sync::OnceCell;
use subvt_metrics::registry::IntGauge;
const METRIC_PREFIX: &str = "subvt_telemetry_processor";
static BEST_BLOCK_NUMBER: OnceCell<IntGauge> = OnceCell::new();
static FINALIZED_BLOCK_NUMBER: OnceCell<IntGauge> = OnceCell::new();
static NODE_COUNT: OnceCell<IntGauge> = OnceCell::new();
pub(crate) fn init() {
if BEST_BLOCK_NUMBER.get().is_none() {
let _ = BEST_BLOCK_NUMBER.set(
subvt_metrics::registry::register_int_gauge(
METRIC_PREFIX,
"best_block_number",
"Number of the network's best block",
)
.unwrap(),
);
}
if FINALIZED_BLOCK_NUMBER.get().is_none() {
let _ = FINALIZED_BLOCK_NUMBER.set(
subvt_metrics::registry::register_int_gauge(
METRIC_PREFIX,
"finalized_block_number",
"Number of the network's finalized block",
)
.unwrap(),
);
}
if NODE_COUNT.get().is_none() {
let _ = NODE_COUNT.set(
subvt_metrics::registry::register_int_gauge(
METRIC_PREFIX,
"node_count",
"Number of nodes connected to this Telemetry instance",
)
.unwrap(),
);
}
}
pub fn best_block_number() -> IntGauge {
BEST_BLOCK_NUMBER.get().unwrap().clone()
}
pub fn finalized_block_number() -> IntGauge {
FINALIZED_BLOCK_NUMBER.get().unwrap().clone()
}
pub fn node_count() -> IntGauge {
NODE_COUNT.get().unwrap().clone()
}