@@ -5,21 +5,23 @@ use crate::server::agents::Agent;
5
5
use chrono:: { DateTime , Utc } ;
6
6
use prometheus:: proto:: { Metric , MetricFamily } ;
7
7
use prometheus:: {
8
- IntCounterVec , IntGauge , IntGaugeVec , __register_counter_vec, __register_gauge,
8
+ HistogramVec , IntCounterVec , IntGauge , IntGaugeVec , __register_counter_vec, __register_gauge,
9
9
__register_gauge_vec,
10
10
} ;
11
11
12
12
const JOBS_METRIC : & str = "crater_completed_jobs_total" ;
13
13
const AGENT_WORK_METRIC : & str = "crater_agent_supposed_to_work" ;
14
14
const AGENT_FAILED : & str = "crater_agent_failure" ;
15
15
const LAST_CRATES_UPDATE_METRIC : & str = "crater_last_crates_update" ;
16
+ const ENDPOINT_TIME : & str = "crater_endpoint_time_seconds" ;
16
17
17
18
#[ derive( Clone ) ]
18
19
pub struct Metrics {
19
20
crater_completed_jobs_total : IntCounterVec ,
20
21
crater_agent_failure : IntCounterVec ,
21
22
crater_work_status : IntGaugeVec ,
22
23
crater_last_crates_update : IntGauge ,
24
+ pub crater_endpoint_time : HistogramVec ,
23
25
}
24
26
25
27
impl Metrics {
@@ -35,12 +37,20 @@ impl Metrics {
35
37
let crates_update_opts =
36
38
prometheus:: opts!( LAST_CRATES_UPDATE_METRIC , "last update of crates lists" ) ;
37
39
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
+ ) ?;
38
47
39
48
Ok ( Metrics {
40
49
crater_completed_jobs_total,
41
50
crater_agent_failure,
42
51
crater_work_status,
43
52
crater_last_crates_update,
53
+ crater_endpoint_time,
44
54
} )
45
55
}
46
56
0 commit comments