1
1
use prometheus_exporter:: prometheus:: {
2
- opts, register_int_gauge_vec_with_registry, IntGaugeVec , Registry ,
2
+ histogram_opts, opts, register_histogram_vec_with_registry,
3
+ register_int_gauge_vec_with_registry, HistogramTimer , HistogramVec , IntGaugeVec , Registry ,
3
4
} ;
4
5
5
6
use crate :: portalnet:: PORTALNET_METRICS ;
@@ -8,6 +9,7 @@ use crate::portalnet::PORTALNET_METRICS;
8
9
#[ derive( Clone , Debug ) ]
9
10
pub struct DownloaderMetrics {
10
11
pub current_block : IntGaugeVec ,
12
+ pub find_content_timer : HistogramVec ,
11
13
}
12
14
13
15
impl DownloaderMetrics {
@@ -20,7 +22,18 @@ impl DownloaderMetrics {
20
22
& [ "downloader" ] ,
21
23
registry
22
24
) ?;
23
- Ok ( Self { current_block } )
25
+ let find_content_timer = register_histogram_vec_with_registry ! (
26
+ histogram_opts!(
27
+ "downloader_find_content_timer" ,
28
+ "the time it takes for find content query to complete"
29
+ ) ,
30
+ & [ "downloader" ] ,
31
+ registry
32
+ ) ?;
33
+ Ok ( Self {
34
+ current_block,
35
+ find_content_timer,
36
+ } )
24
37
}
25
38
}
26
39
@@ -48,4 +61,15 @@ impl DownloaderMetricsReporter {
48
61
. with_label_values ( & [ "downloader" ] )
49
62
. set ( block_number as i64 ) ;
50
63
}
64
+
65
+ pub fn start_find_content_timer ( & self ) -> HistogramTimer {
66
+ self . metrics
67
+ . find_content_timer
68
+ . with_label_values ( & [ "downloader" ] )
69
+ . start_timer ( )
70
+ }
71
+
72
+ pub fn stop_find_content_timer ( & self , timer : HistogramTimer ) {
73
+ timer. observe_duration ( )
74
+ }
51
75
}
0 commit comments