@@ -20,7 +20,7 @@ use std::{
2020 ops:: Add ,
2121 sync:: { atomic:: Ordering , Arc , RwLock } ,
2222 thread:: { self , JoinHandle } ,
23- time:: Duration ,
23+ time:: { Duration , Instant } ,
2424} ;
2525
2626use arc_swap:: access:: Access ;
@@ -47,6 +47,7 @@ use crate::{
4747 } ,
4848 flow_generator:: { flow_map:: Config , FlowMap } ,
4949 handler:: { MiniPacket , PacketHandler } ,
50+ liveness:: { DebugInfo , LivenessHandle } ,
5051 rpc:: get_timestamp,
5152 utils:: {
5253 bytes:: read_u32_be,
@@ -153,6 +154,7 @@ pub(super) struct AnalyzerModeDispatcher {
153154 pub ( super ) pool_raw_size : usize ,
154155 pub ( super ) flow_generator_thread_handler : Option < JoinHandle < ( ) > > ,
155156 pub ( super ) pipeline_thread_handler : Option < JoinHandle < ( ) > > ,
157+ pub ( super ) flow_generator_liveness : LivenessHandle ,
156158 pub ( super ) queue_debugger : Arc < QueueDebugger > ,
157159 pub ( super ) stats_collector : Arc < stats:: Collector > ,
158160 pub ( super ) inner_queue_size : usize ,
@@ -270,6 +272,7 @@ impl AnalyzerModeDispatcher {
270272 let collector_config = base. collector_config . clone ( ) ;
271273 let packet_sequence_output_queue = base. packet_sequence_output_queue . clone ( ) ; // Enterprise Edition Feature: packet-sequence
272274 let stats = base. stats . clone ( ) ;
275+ let liveness = self . flow_generator_liveness . clone ( ) ;
273276 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
274277 let cpu_set = base. options . lock ( ) . unwrap ( ) . cpu_set ;
275278
@@ -280,6 +283,7 @@ impl AnalyzerModeDispatcher {
280283 let mut timestamp_map: HashMap < CaptureNetworkType , Duration > = HashMap :: new ( ) ;
281284 let mut batch = Vec :: with_capacity ( HANDLER_BATCH_SIZE ) ;
282285 let mut output_batch = Vec :: with_capacity ( HANDLER_BATCH_SIZE ) ;
286+ let mut last_liveness = Instant :: now ( ) ;
283287 let mut flow_map = FlowMap :: new (
284288 id as u32 ,
285289 Some ( flow_output_queue) ,
@@ -298,8 +302,13 @@ impl AnalyzerModeDispatcher {
298302 warn ! ( "CPU Affinity({:?}) bind error: {:?}." , & cpu_set, e) ;
299303 }
300304 }
305+ liveness. start ( DebugInfo :: new ( "running" ) ) ;
301306
302307 while !terminated. load ( Ordering :: Relaxed ) {
308+ if last_liveness. elapsed ( ) >= Duration :: from_secs ( 1 ) {
309+ liveness. heartbeat ( DebugInfo :: new ( "running" ) ) ;
310+ last_liveness = Instant :: now ( ) ;
311+ }
303312 let config = Config {
304313 flow : & flow_map_config. load ( ) ,
305314 log_parser : & log_parser_config. load ( ) ,
@@ -433,6 +442,7 @@ impl AnalyzerModeDispatcher {
433442 output_batch. clear ( ) ;
434443 }
435444 }
445+ liveness. stop ( DebugInfo :: new ( "stopped" ) ) ;
436446 } )
437447 . unwrap ( ) ,
438448 ) ;
@@ -543,6 +553,8 @@ impl AnalyzerModeDispatcher {
543553 let id = base. id ;
544554 let mut batch = Vec :: with_capacity ( HANDLER_BATCH_SIZE ) ;
545555 let mut allocator = Allocator :: new ( self . raw_packet_block_size ) ;
556+ let mut last_liveness = Instant :: now ( ) ;
557+ base. liveness_handle . start ( DebugInfo :: new ( "running" ) ) ;
546558 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
547559 let cpu_set = base. options . lock ( ) . unwrap ( ) . cpu_set ;
548560 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
@@ -553,6 +565,10 @@ impl AnalyzerModeDispatcher {
553565 }
554566
555567 while !base. terminated . load ( Ordering :: Relaxed ) {
568+ if last_liveness. elapsed ( ) >= Duration :: from_secs ( 1 ) {
569+ base. liveness_handle . heartbeat ( DebugInfo :: new ( "running" ) ) ;
570+ last_liveness = Instant :: now ( ) ;
571+ }
556572 if base. reset_whitelist . swap ( false , Ordering :: Relaxed ) {
557573 base. tap_interface_whitelist . reset ( ) ;
558574 }
@@ -615,6 +631,7 @@ impl AnalyzerModeDispatcher {
615631 let _ = handler. join ( ) ;
616632 }
617633
634+ base. liveness_handle . stop ( DebugInfo :: new ( "stopped" ) ) ;
618635 self . base . terminate_handler ( ) ;
619636 info ! ( "Stopped dispatcher {}" , self . base. is. log_id) ;
620637 }
0 commit comments