63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Services\Coolify\CoolifyClient;
|
|
use Filament\Widgets\Widget;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class CoolifyPlatformHealth extends Widget
|
|
{
|
|
protected string $view = 'filament.widgets.coolify-platform-health';
|
|
|
|
protected ?string $pollingInterval = '60s';
|
|
|
|
protected function getViewData(): array
|
|
{
|
|
return [
|
|
'services' => $this->loadServices(),
|
|
];
|
|
}
|
|
|
|
protected function loadServices(): array
|
|
{
|
|
$client = app(CoolifyClient::class);
|
|
$serviceMap = config('coolify.services', []);
|
|
$results = [];
|
|
|
|
foreach ($serviceMap as $label => $serviceId) {
|
|
try {
|
|
$status = $client->serviceStatus($serviceId);
|
|
$results[] = [
|
|
'label' => ucfirst($label),
|
|
'service_id' => $serviceId,
|
|
'status' => Arr::get($status, 'data.status', 'unknown'),
|
|
'cpu' => Arr::get($status, 'data.metrics.cpu_percent'),
|
|
'memory' => Arr::get($status, 'data.metrics.memory_percent'),
|
|
'last_deploy' => Arr::get($status, 'data.last_deployment.finished_at'),
|
|
];
|
|
} catch (\Throwable $exception) {
|
|
$results[] = [
|
|
'label' => ucfirst($label),
|
|
'service_id' => $serviceId,
|
|
'status' => 'unreachable',
|
|
'error' => $exception->getMessage(),
|
|
];
|
|
}
|
|
}
|
|
|
|
if (empty($results)) {
|
|
return [
|
|
[
|
|
'label' => 'Coolify',
|
|
'service_id' => '-',
|
|
'status' => 'unconfigured',
|
|
'error' => 'Set COOLIFY_SERVICE_IDS in .env to enable monitoring.',
|
|
],
|
|
];
|
|
}
|
|
|
|
return $results;
|
|
}
|
|
}
|