*/ public array $services = []; public ?string $checkedAt = null; public function mount(): void { $this->refreshHealth(); } public function refreshHealth(): void { $this->services = app(SystemHealth::class)->services(); $this->checkedAt = now()->format('H:i:s'); } public function worstState(): string { $states = array_column($this->services, 'state'); return in_array('offline', $states, true) ? 'offline' : (in_array('warning', $states, true) ? 'warning' : 'online'); } public function problemCount(): int { return count(array_filter($this->services, fn ($s) => $s['state'] !== 'online')); } public function chartConfig(): array { $metrics = Metric::orderByDesc('sampled_at')->limit(60)->get()->reverse()->values(); return [ 'labels' => $metrics->map(fn ($m) => $m->sampled_at->format('H:i'))->all(), 'series' => [ ['key' => 'mqtt', 'label' => __('host.chart_mqtt'), 'color' => '--color-accent', 'axis' => 'y', 'data' => $metrics->pluck('mqtt_messages')->all()], ['key' => 'cpu', 'label' => __('host.chart_cpu'), 'color' => '--color-online', 'axis' => 'y', 'data' => $metrics->pluck('cpu_load')->all()], ['key' => 'mem', 'label' => __('host.chart_mem'), 'color' => '--color-warning', 'axis' => 'y1', 'data' => $metrics->pluck('mem_used_pct')->all()], ], ]; } public function render() { return view('livewire.host', [ 'chart' => $this->chartConfig(), 'hasMetrics' => Metric::exists(), ]); } }