46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Services\SystemHealth;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.app')]
|
|
class Host extends Component
|
|
{
|
|
/** @var array<int, array{key:string,label:string,icon:string,state:string,detail:string}> */
|
|
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 render()
|
|
{
|
|
return view('livewire.host');
|
|
}
|
|
}
|