@@ -5,21 +5,23 @@ use crate::server::agents::Agent;
55use chrono:: { DateTime , Utc } ;
66use prometheus:: proto:: { Metric , MetricFamily } ;
77use prometheus:: {
8- IntCounterVec , IntGauge , IntGaugeVec , __register_counter_vec, __register_gauge,
8+ HistogramVec , IntCounterVec , IntGauge , IntGaugeVec , __register_counter_vec, __register_gauge,
99 __register_gauge_vec,
1010} ;
1111
1212const JOBS_METRIC : & str = "crater_completed_jobs_total" ;
1313const AGENT_WORK_METRIC : & str = "crater_agent_supposed_to_work" ;
1414const AGENT_FAILED : & str = "crater_agent_failure" ;
1515const LAST_CRATES_UPDATE_METRIC : & str = "crater_last_crates_update" ;
16+ const ENDPOINT_TIME : & str = "crater_endpoint_time_seconds" ;
1617
1718#[ derive( Clone ) ]
1819pub struct Metrics {
1920 crater_completed_jobs_total : IntCounterVec ,
2021 crater_agent_failure : IntCounterVec ,
2122 crater_work_status : IntGaugeVec ,
2223 crater_last_crates_update : IntGauge ,
24+ pub crater_endpoint_time : HistogramVec ,
2325}
2426
2527impl Metrics {
@@ -35,12 +37,20 @@ impl Metrics {
3537 let crates_update_opts =
3638 prometheus:: opts!( LAST_CRATES_UPDATE_METRIC , "last update of crates lists" ) ;
3739 let crater_last_crates_update = prometheus:: register_int_gauge!( crates_update_opts) ?;
40+ let crater_endpoint_time = prometheus:: register_histogram_vec!(
41+ prometheus:: HistogramOpts :: new( ENDPOINT_TIME , "duration of endpoint requests" )
42+ // Exponential buckets, with 5ms as start and top bucket ending at
43+ // approximately 5 seconds.
44+ . buckets( prometheus:: exponential_buckets( 0.005 , 1.5 , 17 ) . unwrap( ) ) ,
45+ & [ "endpoint" ]
46+ ) ?;
3847
3948 Ok ( Metrics {
4049 crater_completed_jobs_total,
4150 crater_agent_failure,
4251 crater_work_status,
4352 crater_last_crates_update,
53+ crater_endpoint_time,
4454 } )
4555 }
4656
0 commit comments