1515 */
1616
1717use once_cell:: sync:: Lazy ;
18- use prometheus:: { IntCounterVec , IntGaugeVec , Registry } ;
18+ use prometheus:: { IntGauge , IntCounterVec , IntGaugeVec , Histogram , Registry } ;
1919
2020pub ( crate ) const NODE_LABEL : & str = "node" ;
2121pub ( crate ) const CONTROL_PLANE_LABEL : & str = "control_plane" ;
@@ -38,7 +38,7 @@ pub fn registry() -> &'static Registry {
3838 unsafe { REGISTRY } . expect ( "set_registry must be called" )
3939}
4040
41- pub ( crate ) fn active_control_planes ( control_plane : & str ) -> prometheus :: IntGauge {
41+ pub ( crate ) fn active_control_planes ( control_plane : & str ) -> IntGauge {
4242 static ACTIVE_CONTROL_PLANES : Lazy < IntGaugeVec > = Lazy :: new ( || {
4343 prometheus:: register_int_gauge_vec_with_registry! {
4444 prometheus:: opts! {
@@ -54,6 +54,104 @@ pub(crate) fn active_control_planes(control_plane: &str) -> prometheus::IntGauge
5454 ACTIVE_CONTROL_PLANES . with_label_values ( & [ control_plane] )
5555}
5656
57+ pub ( crate ) fn client_active ( active : bool ) {
58+ static METRIC : Lazy < IntGauge > = Lazy :: new ( || {
59+ prometheus:: register_int_gauge_with_registry! {
60+ prometheus:: opts! {
61+ "provider_grpc_active" ,
62+ "Whether the gRPC configuration provider is active or not (either 1 or 0)." ,
63+ } ,
64+ registry( ) ,
65+ }
66+ . unwrap ( )
67+ } ) ;
68+
69+ METRIC . set ( active as _ ) ;
70+ }
71+
72+ pub ( crate ) fn client_connect_attempts_total ( address : & impl std:: fmt:: Display ) {
73+ static METRIC : Lazy < IntCounterVec > = Lazy :: new ( || {
74+ prometheus:: register_int_counter_vec_with_registry! {
75+ prometheus:: opts! {
76+ "provider_grpc_connect_attempts_total" ,
77+ "total number of attempts the gRPC provider has made to connect to `address`." ,
78+ } ,
79+ & [ "address" ] ,
80+ registry( ) ,
81+ }
82+ . unwrap ( )
83+ } ) ;
84+
85+ METRIC . with_label_values ( & [ & address. to_string ( ) ] ) . inc ( ) ;
86+ }
87+
88+ pub ( crate ) fn client_errors_total ( reason : & impl std:: fmt:: Display ) {
89+ static METRIC : Lazy < IntCounterVec > = Lazy :: new ( || {
90+ prometheus:: register_int_counter_vec_with_registry! {
91+ prometheus:: opts! {
92+ "provider_grpc_errors_total" ,
93+ "total number of errors the gRPC provider has encountered" ,
94+ } ,
95+ & [ "reason" ] ,
96+ registry( ) ,
97+ }
98+ . unwrap ( )
99+ } ) ;
100+
101+ METRIC . with_label_values ( & [ & reason. to_string ( ) ] ) . inc ( ) ;
102+ }
103+
104+ pub fn client_connect_attempt_backoff_millis ( delay : std:: time:: Duration ) {
105+ pub ( crate ) const BUCKET_START : f64 = 0.001 ;
106+ pub ( crate ) const BUCKET_FACTOR : f64 = 2.0 ;
107+ pub ( crate ) const BUCKET_COUNT : usize = 13 ;
108+
109+ static METRIC : Lazy < Histogram > = Lazy :: new ( || {
110+ prometheus:: register_histogram_with_registry! {
111+ prometheus:: histogram_opts! {
112+ "provider_grpc_connect_attempt_backoff_seconds" ,
113+ "The backoff duration made when attempting reconnect to a gRPC provider" ,
114+ prometheus:: exponential_buckets( BUCKET_START , BUCKET_FACTOR , BUCKET_COUNT ) . unwrap( ) ,
115+ } ,
116+ registry( ) ,
117+ }
118+ . unwrap ( )
119+ } ) ;
120+
121+ METRIC . observe ( delay. as_secs_f64 ( ) ) ;
122+ }
123+
124+ pub ( crate ) fn server_active ( active : bool ) {
125+ static METRIC : Lazy < IntGauge > = Lazy :: new ( || {
126+ prometheus:: register_int_gauge_with_registry! {
127+ prometheus:: opts! {
128+ "service_grpc_active" ,
129+ "Whether the gRPC service is active or not (either 1 or 0)." ,
130+ } ,
131+ registry( ) ,
132+ }
133+ . unwrap ( )
134+ } ) ;
135+
136+ METRIC . set ( active as _ ) ;
137+ }
138+
139+ pub ( crate ) fn server_resource_updates_total ( resource : & str ) {
140+ static METRIC : Lazy < IntCounterVec > = Lazy :: new ( || {
141+ prometheus:: register_int_counter_vec_with_registry! {
142+ prometheus:: opts! {
143+ "service_grpc_resource_updates_total" ,
144+ "total number of updates to a `resource` being sent to gRPC clients." ,
145+ } ,
146+ & [ "address" ] ,
147+ registry( ) ,
148+ }
149+ . unwrap ( )
150+ } ) ;
151+
152+ METRIC . with_label_values ( & [ resource] ) . inc ( ) ;
153+ }
154+
57155pub ( crate ) fn delta_discovery_requests ( node : & str , type_url : & str ) -> prometheus:: IntCounter {
58156 static DELTA_DISCOVERY_REQUESTS : Lazy < IntCounterVec > = Lazy :: new ( || {
59157 prometheus:: register_int_counter_vec_with_registry! {
0 commit comments