'' AND cluster NOT LIKE '%-WM%' AND cluster NOT LIKE '%-C1MAS%' AND cluster NOT LIKE '%-vrs%' AND (cluster LIKE 'DUN%' OR cluster LIKE 'DMV%') GROUP BY cluster ORDER BY cluster "; $all_clusters_data = Invoke_Infra($cluster_query); $vm_repart_query = " SELECT v.Cluster, v.Owner, count(v.Owner) as vm_count FROM cmdb_vms v INNER JOIN cmdb_HyperV_Hosts h ON v.Cluster = h.cluster WHERE v.decomtime IS NULL AND h.cluster <> '' AND h.cluster NOT LIKE '%-WM%' AND h.cluster NOT LIKE '%-C1MAS%' AND h.cluster NOT LIKE '%-vrs%' AND (h.cluster LIKE 'DUN%' OR h.cluster LIKE 'DMV%') GROUP BY v.Cluster, v.Owner ORDER BY v.Cluster, v.Owner "; $raw_vm_distribution = Invoke_Infra($vm_repart_query); $vm_distribution = []; if (is_array($raw_vm_distribution)) { foreach ($raw_vm_distribution as $repart) { $vm_distribution[$repart['Cluster']][] = [ 'owner' => $repart['Owner'], 'vm_count' => $repart['vm_count'] ]; } } $vm_issues_query = " SELECT v.Cluster, SUM(CASE WHEN v.IsClustered = 'False' THEN 1 ELSE 0 END) as unclustered_count, SUM(CASE WHEN v.IsClustered = 'True' AND v.Owner <> v.PreferredOwner THEN 1 ELSE 0 END) as wrong_owner_count FROM cmdb_vms v WHERE v.decomtime IS NULL AND v.Cluster <> '' AND v.Cluster NOT LIKE '%-WM%' AND v.Cluster NOT LIKE '%-C1MAS%' AND v.Cluster NOT LIKE '%-vrs%' AND (v.Cluster LIKE 'DUN%' OR v.Cluster LIKE 'DMV%') GROUP BY v.Cluster "; $raw_vm_issues = Invoke_Infra($vm_issues_query); $vm_issues = []; if (is_array($raw_vm_issues)) { foreach ($raw_vm_issues as $issue) { $vm_issues[$issue['Cluster']] = [ 'unclustered' => $issue['unclustered_count'], 'wrong_owner' => $issue['wrong_owner_count'] ]; } } // ================================================================= // STEP 2: Loop through the pre-fetched data and display it // ================================================================= $total_vms_left = 0; $cluster_count = 0; if (is_array($all_clusters_data)) { foreach ($all_clusters_data as $cluster_data) { if ($cluster_count > 0 && $cluster_count % 4 == 0) { echo "
"; } // --- Calculations --- $cluster_name = $cluster_data['cluster']; $node_count = (int)$cluster_data['node_count']; $total_vms = (int)$cluster_data['total_vms']; $total_vm_memory = (int)$cluster_data['total_vm_memory']; // Memory calculation $cluster_usable_mem = (int)$cluster_data['min_node_ram'] - 32; if ($node_count == 4) { $cluster_usable_mem *= 2; } $free_mem = $cluster_usable_mem - $total_vm_memory; $free_mem_percentage = ($cluster_usable_mem > 0) ? round($free_mem / $cluster_usable_mem * 100) : 0; // Storage calculation $capacity_gb = 0; $free_gb = 0; if (!empty($cluster_data['all_csvs'])) { $all_csv_entries = explode("|", $cluster_data['all_csvs']); $unique_csv_entries = array_unique($all_csv_entries); foreach ($unique_csv_entries as $csv_string) { if (str_contains($csv_string, ';')) { $parts = explode(";", $csv_string); if(count($parts) >= 3) { $capacity_gb += (int)$parts[1]; $free_gb += (int)$parts[1] - (int)$parts[2]; } } } } $free_gb = max(0, $free_gb); $free_storage_percentage = ($capacity_gb > 0) ? round($free_gb / $capacity_gb * 100) : 0; // VMs Left Calculation $vms_left_by_mem = ($free_mem > 0) ? floor($free_mem / 16) : 0; $vms_left_by_storage = ($free_gb > 0) ? floor($free_gb / 110) : 0; $vms_left = min($vms_left_by_mem, $vms_left_by_storage); $total_vms_left += $vms_left; // --- Display Logic --- if ($vms_left > 2) { $vleft_html = "(" . $vms_left . " $w_VMleft)"; } elseif ($vms_left >= 1) { $vleft_html = "(" . $vms_left . " $w_VMleft)"; } else { $vleft_html = "(" . $vms_left . " $w_VMleft)"; } ?>


Total :