@@ -82,10 +82,23 @@ def get_time_interval_value(start_time: datetime, end_time: datetime, interval:
8282
8383
8484def profiling_host_status_params (
85- service_name : Optional [str ] = Query (None , description = "Filter by service name" ),
85+ service_name : Optional [List [ str ]] = Query (None , description = "Filter by service name(s) " ),
8686 exact_match : bool = Query (False , description = "Use exact match for service name (default: false for partial matching)" ),
87+ hostname : Optional [List [str ]] = Query (None , description = "Filter by hostname(s)" ),
88+ ip_address : Optional [List [str ]] = Query (None , description = "Filter by IP address(es)" ),
89+ profiling_status : Optional [List [str ]] = Query (None , description = "Filter by profiling status(es) (e.g., pending, completed, stopped)" ),
90+ command_type : Optional [List [str ]] = Query (None , description = "Filter by command type(s) (e.g., start, stop)" ),
91+ pids : Optional [List [int ]] = Query (None , description = "Filter by PIDs" ),
8792) -> ProfilingHostStatusRequest :
88- return ProfilingHostStatusRequest (service_name = service_name , exact_match = exact_match )
93+ return ProfilingHostStatusRequest (
94+ service_name = service_name ,
95+ exact_match = exact_match ,
96+ hostname = hostname ,
97+ ip_address = ip_address ,
98+ profiling_status = profiling_status ,
99+ command_type = command_type ,
100+ pids = pids ,
101+ )
89102
90103
91104@router .get ("/instance_type_count" , response_model = List [InstanceTypeCount ])
@@ -647,19 +660,31 @@ def get_profiling_host_status(
647660 profiling_params : ProfilingHostStatusRequest = Depends (profiling_host_status_params ),
648661):
649662 """
650- Get profiling host status with optional service name filtering .
663+ Get profiling host status with optional filtering by multiple parameters .
651664
652665 Args:
653- profiling_params: ProfilingHostStatusRequest object containing service name and exact match flag
666+ profiling_params: ProfilingHostStatusRequest object containing all filter parameters
654667
655668 Returns:
656- List of host statuses
669+ List of host statuses filtered by the specified criteria
657670 """
658671 db_manager = DBManager ()
659672
660673 # Get hosts - filter by service_name if provided
661674 if profiling_params .service_name :
662- hosts = db_manager .get_host_heartbeats_by_service (profiling_params .service_name , exact_match = profiling_params .exact_match )
675+ # For multiple service names, we need to get hosts for each service and combine
676+ all_hosts = []
677+ for service_name in profiling_params .service_name :
678+ hosts = db_manager .get_host_heartbeats_by_service (service_name , exact_match = profiling_params .exact_match )
679+ all_hosts .extend (hosts )
680+ # Remove duplicates based on hostname + service_name combination
681+ seen = set ()
682+ hosts = []
683+ for host in all_hosts :
684+ key = (host .get ("hostname" ), host .get ("service_name" ))
685+ if key not in seen :
686+ seen .add (key )
687+ hosts .append (host )
663688 else :
664689 hosts = db_manager .get_all_host_heartbeats ()
665690
@@ -668,24 +693,63 @@ def get_profiling_host_status(
668693 hostname = host .get ("hostname" )
669694 host_service_name = host .get ("service_name" )
670695 ip_address = host .get ("ip_address" )
671- pids = "All" # Placeholder, update if you have per-host PID info
696+
697+ # Apply hostname filter (check if hostname matches any in the list)
698+ if profiling_params .hostname and not any (filter_hostname .lower () in hostname .lower () for filter_hostname in profiling_params .hostname ):
699+ continue
700+
701+ # Apply IP address filter (check if IP matches any in the list)
702+ if profiling_params .ip_address and not any (filter_ip in ip_address for filter_ip in profiling_params .ip_address ):
703+ continue
672704
673705 # Get current profiling command for this host/service
674706 command = db_manager .get_current_profiling_command (hostname , host_service_name )
675707 if command :
676708 profiling_status = command .get ("status" )
677709 command_type = command .get ("command_type" , "N/A" )
710+ # Extract PIDs from command config if available
711+ combined_config = command .get ("combined_config" , {})
712+ if isinstance (combined_config , str ):
713+ try :
714+ combined_config = json .loads (combined_config )
715+ except json .JSONDecodeError :
716+ combined_config = {}
717+
718+ # Try to get PIDs from the command configuration
719+ command_pids = []
720+ if isinstance (combined_config , dict ):
721+ pids_in_config = combined_config .get ("pids" , [])
722+ if isinstance (pids_in_config , list ):
723+ # Convert to integers, filtering out non-numeric values
724+ command_pids = [int (pid ) for pid in pids_in_config if str (pid ).isdigit ()]
678725 else :
679726 profiling_status = "stopped"
680727 command_type = "N/A"
728+ command_pids = []
729+
730+ # Apply profiling status filter (check if status matches any in the list)
731+ if profiling_params .profiling_status and not any (filter_status .lower () == profiling_status .lower () for filter_status in profiling_params .profiling_status ):
732+ continue
733+
734+ # Apply command type filter (check if command type matches any in the list)
735+ if profiling_params .command_type and not any (filter_cmd_type .lower () == command_type .lower () for filter_cmd_type in profiling_params .command_type ):
736+ continue
737+
738+ # Apply PIDs filter (check if any filter PID matches the command PIDs)
739+ if profiling_params .pids and command_pids :
740+ if not any (filter_pid in command_pids for filter_pid in profiling_params .pids ):
741+ continue
742+ elif profiling_params .pids and not command_pids :
743+ # If filtering by PIDs but no PIDs in command, skip this host
744+ continue
681745
682746 results .append (
683747 ProfilingHostStatus (
684748 id = host .get ("id" , 0 ),
685749 service_name = host_service_name ,
686750 hostname = hostname ,
687751 ip_address = ip_address ,
688- pids = pids ,
752+ pids = command_pids ,
689753 command_type = command_type ,
690754 profiling_status = profiling_status ,
691755 heartbeat_timestamp = host .get ("heartbeat_timestamp" ),
0 commit comments