get(); $vmStats = VirtualMachine::selectRaw(' COUNT(*) as total, SUM(CASE WHEN status = "running" THEN 1 ELSE 0 END) as running, SUM(CASE WHEN status = "stopped" THEN 1 ELSE 0 END) as stopped, AVG(cpu_usage) as avg_cpu, AVG(memory_usage) as avg_memory ')->first(); $containerStats = Container::selectRaw(' COUNT(*) as total, SUM(CASE WHEN state = "running" THEN 1 ELSE 0 END) as running, SUM(CASE WHEN state = "exited" THEN 1 ELSE 0 END) as stopped ')->first(); $endpoints = DockerEndpoint::select('id', 'name', 'type', 'status')->get(); $cloudAccounts = CloudAccount::select('id', 'name', 'provider', 'status')->get(); $criticalAlerts = Alert::where('status', 'firing')->where('severity', 'critical')->count(); $warningAlerts = Alert::where('status', 'firing')->where('severity', 'warning')->count(); $recentAlerts = Alert::with('rule') ->where('status', 'firing') ->orderByDesc('created_at') ->limit(5) ->get(); $avgSecurityScore = SecurityScore::avg('score') ?? 0; return Inertia::render('Dashboard/Index', [ 'stats' => [ 'hypervisors' => $hypervisors->count(), 'hypervisors_online' => $hypervisors->where('status', 'online')->count(), 'vms' => (int) ($vmStats->total ?? 0), 'vms_running' => (int) ($vmStats->running ?? 0), 'vms_stopped' => (int) ($vmStats->stopped ?? 0), 'avg_cpu' => round((float) ($vmStats->avg_cpu ?? 0), 1), 'avg_memory' => round((float) ($vmStats->avg_memory ?? 0), 1), 'containers' => (int) ($containerStats->total ?? 0), 'containers_running' => (int) ($containerStats->running ?? 0), 'cloud_accounts' => $cloudAccounts->count(), 'critical_alerts' => $criticalAlerts, 'warning_alerts' => $warningAlerts, 'security_score' => round($avgSecurityScore, 1), ], 'hypervisors' => $hypervisors, 'endpoints' => $endpoints, 'cloud_accounts' => $cloudAccounts, 'recent_alerts' => $recentAlerts, ]); } }