@@ -23,6 +23,14 @@ pub enum MonitorCommands {
2323 name = "connections" ,
2424 about = "Monitor the recent connections detected by the identity service"
2525 ) ] Connections ,
26+ #[ command(
27+ name = "latencymetrics" ,
28+ about = "Monitor the latency metrics detected by the metrics service"
29+ ) ] Latencymetrics ,
30+ #[ command(
31+ name = "droppedpackets" ,
32+ about = "Monitor the dropped packets metrics detected by the metrics service"
33+ ) ] Droppedpackets ,
2634}
2735
2836// cfcli monitor <args>
@@ -140,3 +148,120 @@ pub async fn monitor_identity_events() -> Result<(), Error> {
140148
141149 Ok ( ( ) )
142150}
151+
152+ pub async fn monitor_latency_metrics ( ) -> Result < ( ) , Error > {
153+ //function to monitor latency metrics
154+ println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Connecting to cortexflow Client" . white( ) ) ;
155+
156+ match connect_to_client ( ) . await {
157+ Ok ( client) => {
158+ println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Connected to CortexFlow Client" . green( ) ) ;
159+ //send request to get latency metrics
160+ match agent_api:: requests:: send_latency_metrics_request ( client) . await {
161+ Ok ( response) => {
162+ let resp = response. into_inner ( ) ;
163+ if resp. metrics . is_empty ( ) {
164+ println ! ( "{} No latency metrics found" , "=====>" . blue( ) . bold( ) ) ;
165+ } else {
166+ println ! ( "{} Found {} latency metrics" , "=====>" . blue( ) . bold( ) , resp. metrics. len( ) ) ;
167+ for ( i, metric) in resp. metrics . iter ( ) . enumerate ( ) {
168+ println ! (
169+ "index {} Latency[{}], tgid {} process_name {} address_family {} delta_us {} src_address_v4 {} dst_address_v4 {} src_address_v6 {} dst_address_v6 {} local_port {} remote_port {} timestamp_us {}" ,
170+ "=====>" . blue( ) . bold( ) ,
171+ i,
172+ metric. tgid,
173+ metric. process_name,
174+ metric. address_family,
175+ metric. delta_us,
176+ metric. src_address_v4,
177+ metric. dst_address_v4,
178+ format!( "{:?}" , metric. src_address_v6) ,
179+ format!( "{:?}" , metric. dst_address_v6) ,
180+ metric. local_port,
181+ metric. remote_port,
182+ metric. timestamp_us
183+ ) ;
184+ }
185+ }
186+ }
187+ Err ( e) => {
188+ println ! (
189+ "{} {} {} {}" ,
190+ "=====>" . blue( ) . bold( ) ,
191+ "An error occured" . red( ) ,
192+ "Error:" ,
193+ e
194+ ) ;
195+ return Err ( e) ;
196+ }
197+ }
198+ }
199+ Err ( e) =>{
200+ println ! (
201+ "{} {}" ,
202+ "=====>" . blue( ) . bold( ) ,
203+ "Failed to connect to CortexFlow Client" . red( )
204+ ) ;
205+ return Err ( e) ;
206+ }
207+ }
208+ Ok ( ( ) )
209+ }
210+
211+ pub async fn monitor_dropped_packets ( ) -> Result < ( ) , Error > {
212+ //function to monitor dropped packets metrics
213+ println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Connecting to cortexflow Client" . white( ) ) ;
214+
215+ match connect_to_client ( ) . await {
216+ Ok ( client) => {
217+ println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Connected to CortexFlow Client" . green( ) ) ;
218+ //send request to get dropped packets metrics
219+ match agent_api:: requests:: send_dropped_packets_request ( client) . await {
220+ Ok ( response) => {
221+ let resp = response. into_inner ( ) ;
222+ if resp. metrics . is_empty ( ) {
223+ println ! ( "{} No dropped packets metrics found" , "=====>" . blue( ) . bold( ) ) ;
224+ } else {
225+ println ! ( "{} Found {} dropped packets metrics" , "=====>" . blue( ) . bold( ) , resp. metrics. len( ) ) ;
226+ for ( i, metric) in resp. metrics . iter ( ) . enumerate ( ) {
227+ println ! (
228+ "{} DroppedPackets[{}]\n TGID: {}\n Process: {}\n SK Drops: {}\n Socket Errors: {}\n Soft Errors: {}\n Backlog Length: {}\n Write Memory Queued: {}\n Receive Buffer Size: {}\n ACK Backlog: {}\n Timestamp: {} µs" ,
229+ "=====>" . blue( ) . bold( ) ,
230+ i,
231+ metric. tgid,
232+ metric. process_name,
233+ metric. sk_drops,
234+ metric. sk_err,
235+ metric. sk_err_soft,
236+ metric. sk_backlog_len,
237+ metric. sk_wmem_queued,
238+ metric. sk_rcvbuf,
239+ metric. sk_ack_backlog,
240+ metric. timestamp_us
241+ ) ;
242+ }
243+ }
244+ }
245+ Err ( e) => {
246+ println ! (
247+ "{} {} {} {}" ,
248+ "=====>" . blue( ) . bold( ) ,
249+ "An error occured" . red( ) ,
250+ "Error:" ,
251+ e
252+ ) ;
253+ return Err ( e) ;
254+ }
255+ }
256+ }
257+ Err ( e) =>{
258+ println ! (
259+ "{} {}" ,
260+ "=====>" . blue( ) . bold( ) ,
261+ "Failed to connect to CortexFlow Client" . red( )
262+ ) ;
263+ return Err ( e) ;
264+ }
265+ }
266+ Ok ( ( ) )
267+ }
0 commit comments