fuel_metrics/
p2p_metrics.rs

1use lazy_static::lazy_static;
2use once_cell::race::OnceBox;
3use prometheus_client::{
4    metrics::counter::Counter,
5    registry::Registry,
6};
7use std::boxed::Box;
8
9pub struct P2PMetrics {
10    pub gossip_sub_registry: OnceBox<Registry>,
11    // For descriptions of each Counter, see the `new` function where each Counter/Histogram is initialized
12    pub peer_metrics: Registry,
13    pub unique_peers: Counter,
14}
15
16impl P2PMetrics {
17    fn new() -> Self {
18        let peer_metrics = Registry::default();
19
20        let unique_peers = Counter::default();
21
22        let mut metrics = P2PMetrics {
23            gossip_sub_registry: OnceBox::new(),
24            peer_metrics,
25            unique_peers,
26        };
27
28        metrics.peer_metrics.register(
29            "Peer_Counter",
30            "A Counter which keeps track of each unique peer the p2p service has connected to",
31            Box::new(metrics.unique_peers.clone()),
32        );
33
34        metrics
35    }
36}
37
38lazy_static! {
39    pub static ref P2P_METRICS: P2PMetrics = P2PMetrics::new();
40}