diff --git a/ceph_osd_analyzer.py b/ceph_osd_analyzer.py index 498669d..7aafecd 100644 --- a/ceph_osd_analyzer.py +++ b/ceph_osd_analyzer.py @@ -430,9 +430,11 @@ def calculate_resilience_score(osd_data, host_name, all_hosts_data, osd_tree): # Performance metrics removed for simplicity -def analyze_cluster(): +def analyze_cluster(class_filter=None, min_size=0): """Main analysis function""" - print(f"{Colors.BOLD}{Colors.CYAN}=== Ceph OSD Replacement Candidate Analyzer ==={Colors.END}\n") + filter_desc = f" [{class_filter.upper()}]" if class_filter else "" + filter_desc += f" [min {min_size}TB]" if min_size else "" + print(f"{Colors.BOLD}{Colors.CYAN}=== Ceph OSD Replacement Candidate Analyzer{filter_desc} ==={Colors.END}\n") # Gather data print("Gathering cluster data...") @@ -468,24 +470,31 @@ def analyze_cluster(): print("Analyzing OSDs across all cluster nodes...\n") - total_osds = len([n for n in osd_tree['nodes'] if n['type'] == 'osd' and n.get('status') == 'up']) + total_osds = len([n for n in osd_tree['nodes'] + if n['type'] == 'osd' and n.get('status') == 'up' + and (not class_filter or n.get('device_class', 'hdd') == class_filter)]) current_osd = 0 - + for node in osd_tree['nodes']: if node['type'] != 'osd' or node.get('status') != 'up': continue - - current_osd += 1 + osd_id = node['id'] osd_name = node['name'] device_class = node.get('device_class', 'hdd') host_name = osd_to_host.get(osd_id, 'unknown') + + if class_filter and device_class != class_filter: + continue + + osd_df_data = osd_df_map.get(osd_id, {}) + if min_size and osd_df_data.get('crush_weight', 0) < min_size: + continue + + current_osd += 1 print(f"[{current_osd}/{total_osds}] Analyzing {osd_name} on {host_name} ({device_class})...".ljust(80), end='\r') - # Get OSD data - osd_df_data = osd_df_map.get(osd_id, {}) - # SMART health analysis health_data = get_device_health(osd_id, host_name) if not health_data: @@ -635,7 +644,7 @@ if __name__ == "__main__": DEBUG = True try: - analyze_cluster() + analyze_cluster(class_filter=args.device_class, min_size=args.min_size) except KeyboardInterrupt: print(f"\n{Colors.YELLOW}Analysis interrupted{Colors.END}") sys.exit(0)