20
20
futures:: StreamExt ,
21
21
prometheus_client:: {
22
22
encoding:: EncodeLabelSet ,
23
- metrics:: { counter:: Counter , family:: Family , gauge:: Gauge } ,
23
+ metrics:: { counter:: Counter , family:: Family , gauge:: Gauge , histogram :: Histogram } ,
24
24
registry:: Registry ,
25
25
} ,
26
26
std:: {
@@ -62,7 +62,6 @@ pub struct AccountLabel {
62
62
pub address : String ,
63
63
}
64
64
65
- #[ derive( Default ) ]
66
65
pub struct KeeperMetrics {
67
66
pub current_sequence_number : Family < AccountLabel , Gauge > ,
68
67
pub end_sequence_number : Family < AccountLabel , Gauge > ,
@@ -74,6 +73,33 @@ pub struct KeeperMetrics {
74
73
pub requests_processed : Family < AccountLabel , Counter > ,
75
74
pub requests_reprocessed : Family < AccountLabel , Counter > ,
76
75
pub reveals : Family < AccountLabel , Counter > ,
76
+ pub request_duration_ms : Family < AccountLabel , Histogram > ,
77
+ }
78
+
79
+ impl Default for KeeperMetrics {
80
+ fn default ( ) -> Self {
81
+ Self {
82
+ current_sequence_number : Family :: default ( ) ,
83
+ end_sequence_number : Family :: default ( ) ,
84
+ balance : Family :: default ( ) ,
85
+ collected_fee : Family :: default ( ) ,
86
+ current_fee : Family :: default ( ) ,
87
+ total_gas_spent : Family :: default ( ) ,
88
+ requests : Family :: default ( ) ,
89
+ requests_processed : Family :: default ( ) ,
90
+ requests_reprocessed : Family :: default ( ) ,
91
+ reveals : Family :: default ( ) ,
92
+ request_duration_ms : Family :: new_with_constructor ( || {
93
+ Histogram :: new (
94
+ vec ! [
95
+ 1000.0 , 2500.0 , 5000.0 , 7500.0 , 10000.0 , 20000.0 , 30000.0 , 40000.0 ,
96
+ 50000.0 , 60000.0 ,
97
+ ]
98
+ . into_iter ( ) ,
99
+ )
100
+ } ) ,
101
+ }
102
+ }
77
103
}
78
104
79
105
impl KeeperMetrics {
@@ -141,6 +167,12 @@ impl KeeperMetrics {
141
167
keeper_metrics. requests_reprocessed . clone ( ) ,
142
168
) ;
143
169
170
+ writable_registry. register (
171
+ "request_duration_ms" ,
172
+ "Time taken to process each callback request in milliseconds" ,
173
+ keeper_metrics. request_duration_ms . clone ( ) ,
174
+ ) ;
175
+
144
176
keeper_metrics
145
177
}
146
178
}
@@ -342,6 +374,8 @@ pub async fn process_event_with_backoff(
342
374
gas_limit : U256 ,
343
375
metrics : Arc < KeeperMetrics > ,
344
376
) {
377
+ let start_time = std:: time:: Instant :: now ( ) ;
378
+
345
379
metrics
346
380
. requests
347
381
. get_or_create ( & AccountLabel {
@@ -372,6 +406,16 @@ pub async fn process_event_with_backoff(
372
406
tracing:: error!( "Failed to process event: {:?}" , e) ;
373
407
}
374
408
}
409
+
410
+ let duration_ms = start_time. elapsed ( ) . as_millis ( ) as f64 ;
411
+ metrics
412
+ . request_duration_ms
413
+ . get_or_create ( & AccountLabel {
414
+ chain_id : chain_state. id . clone ( ) ,
415
+ address : chain_state. provider_address . to_string ( ) ,
416
+ } )
417
+ . observe ( duration_ms) ;
418
+
375
419
metrics
376
420
. requests_processed
377
421
. get_or_create ( & AccountLabel {
0 commit comments