File tree 3 files changed +13
-5
lines changed
3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,10 @@ use prometheus_exporter::{
10
10
} ,
11
11
} ;
12
12
13
- /// TODO COMMENTS ON SETUP
13
+ /// Contains metrics reporters for use in the overlay network
14
+ /// (eg. `portalnet/src/overlay.rs` & `portalnet/src/overlay_service.rs`).
15
+ /// Metric types reported here include protocol messages, utp transfers,
16
+ /// and content validation.
14
17
#[ derive( Clone ) ]
15
18
pub struct OverlayMetrics {
16
19
pub message_count : IntCounterVec ,
Original file line number Diff line number Diff line change 1
1
use crate :: metrics:: overlay:: OverlayMetrics ;
2
2
use crate :: metrics:: storage:: StorageMetrics ;
3
3
use lazy_static:: lazy_static;
4
- use prometheus_exporter:: prometheus:: Registry ;
4
+ use prometheus_exporter:: prometheus:: { default_registry , Registry } ;
5
5
6
+ // We use lazy_static to ensure that the metrics registry is initialized only once, for each
7
+ // runtime. This is important because the registry is a global singleton, and if it is
8
+ // initialized more than once, it will panic when trying to register the same metric for each
9
+ // subnetwork.
6
10
lazy_static ! {
7
11
pub static ref PORTALNET_METRICS : PortalnetMetrics = initialize_metrics_registry( ) ;
8
12
}
9
13
10
14
fn initialize_metrics_registry ( ) -> PortalnetMetrics {
11
- let registry = Registry :: new ( ) ;
12
- PortalnetMetrics :: new ( registry) . expect ( "failed to initialize metrics" )
15
+ PortalnetMetrics :: new ( ) . expect ( "failed to initialize metrics" )
13
16
}
14
17
15
18
pub struct PortalnetMetrics {
@@ -18,7 +21,8 @@ pub struct PortalnetMetrics {
18
21
}
19
22
20
23
impl PortalnetMetrics {
21
- pub fn new ( registry : Registry ) -> anyhow:: Result < Self > {
24
+ pub fn new ( ) -> anyhow:: Result < Self > {
25
+ let registry = default_registry ( ) ;
22
26
let overlay = OverlayMetrics :: new ( & registry) ?;
23
27
let storage = StorageMetrics :: new ( & registry) ?;
24
28
Ok ( Self { overlay, storage } )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use prometheus_exporter::{
7
7
} ,
8
8
} ;
9
9
10
+ /// Contains metrics reporters for portalnet storage.
10
11
#[ derive( Clone , Debug ) ]
11
12
pub struct StorageMetrics {
12
13
pub content_storage_usage_bytes : GaugeVec ,
You can’t perform that action at this time.
0 commit comments