@@ -41,6 +41,7 @@ use crate::{
4141 modal:: { NodeMetadata , NodeType } ,
4242 } ,
4343 } ,
44+ metrics:: { ACTIVE_NODES , INACTIVE_NODES } ,
4445 option:: Mode ,
4546 parseable:: PARSEABLE ,
4647 stats:: { self , Stats } ,
@@ -114,8 +115,7 @@ impl Report {
114115 let ingestor_metrics = fetch_ingestors_metrics ( ) . await ?;
115116 let mut active_indexers = 0 ;
116117 let mut inactive_indexers = 0 ;
117- let mut active_queriers = 0 ;
118- let mut inactive_queriers = 0 ;
118+ let ( active_queriers, inactive_queriers) = fetch_node_counts ( NodeType :: Querier ) . await ?;
119119
120120 // check liveness of indexers
121121 // get the count of active and inactive indexers
@@ -129,17 +129,6 @@ impl Report {
129129 }
130130 }
131131
132- // check liveness of queriers
133- // get the count of active and inactive queriers
134- let query_infos: Vec < NodeMetadata > =
135- cluster:: get_node_info ( NodeType :: Querier , & None ) . await ?;
136- for query in query_infos {
137- if check_liveness ( & query. domain_name ) . await {
138- active_queriers += 1 ;
139- } else {
140- inactive_queriers += 1 ;
141- }
142- }
143132 Ok ( Self {
144133 deployment_id : storage:: StorageMetadata :: global ( ) . deployment_id ,
145134 uptime : upt,
@@ -183,6 +172,42 @@ impl Report {
183172 }
184173}
185174
175+ pub async fn fetch_cluster_node_counts ( ) -> anyhow:: Result < ( ) > {
176+ let ( active_ingestors, inactive_ingestors) = fetch_node_counts ( NodeType :: Ingestor ) . await ?;
177+ let ( active_queriers, inactive_queriers) = fetch_node_counts ( NodeType :: Querier ) . await ?;
178+
179+ ACTIVE_NODES
180+ . with_label_values ( & [ "ingestor" ] )
181+ . set ( i64:: try_from ( active_ingestors) . unwrap_or ( i64:: MAX ) ) ;
182+ INACTIVE_NODES
183+ . with_label_values ( & [ "ingestor" ] )
184+ . set ( i64:: try_from ( inactive_ingestors) . unwrap_or ( i64:: MAX ) ) ;
185+ ACTIVE_NODES
186+ . with_label_values ( & [ "querier" ] )
187+ . set ( i64:: try_from ( active_queriers) . unwrap_or ( i64:: MAX ) ) ;
188+ INACTIVE_NODES
189+ . with_label_values ( & [ "querier" ] )
190+ . set ( i64:: try_from ( inactive_queriers) . unwrap_or ( i64:: MAX ) ) ;
191+
192+ Ok ( ( ) )
193+ }
194+
195+ async fn fetch_node_counts ( node_type : NodeType ) -> anyhow:: Result < ( u64 , u64 ) > {
196+ let mut active_nodes = 0 ;
197+ let mut inactive_nodes = 0 ;
198+ let node_infos: Vec < NodeMetadata > = cluster:: get_node_info ( node_type, & None ) . await ?;
199+
200+ for node in node_infos {
201+ if check_liveness ( & node. domain_name ) . await {
202+ active_nodes += 1 ;
203+ } else {
204+ inactive_nodes += 1 ;
205+ }
206+ }
207+
208+ Ok ( ( active_nodes, inactive_nodes) )
209+ }
210+
186211/// build the node metrics for the node ingestor endpoint
187212pub async fn get_analytics ( _: HttpRequest ) -> impl Responder {
188213 let json = NodeMetrics :: build ( ) ;
0 commit comments