11use 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 ,
34} ;
45
56use crate :: portalnet:: PORTALNET_METRICS ;
@@ -8,6 +9,7 @@ use crate::portalnet::PORTALNET_METRICS;
89#[ derive( Clone , Debug ) ]
910pub struct DownloaderMetrics {
1011 pub current_block : IntGaugeVec ,
12+ pub find_content_timer : HistogramVec ,
1113}
1214
1315impl DownloaderMetrics {
@@ -20,7 +22,18 @@ impl DownloaderMetrics {
2022 & [ "downloader" ] ,
2123 registry
2224 ) ?;
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+ } )
2437 }
2538}
2639
@@ -48,4 +61,15 @@ impl DownloaderMetricsReporter {
4861 . with_label_values ( & [ "downloader" ] )
4962 . set ( block_number as i64 ) ;
5063 }
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+ }
5175}
0 commit comments