admin widget zu dokploy geswitched, viele übersetzungen im Frontend vervollständigt und Anlässe-Seiten mit ChatGPT ausgebaut
This commit is contained in:
@@ -15,49 +15,38 @@ class DokployPlatformHealth extends Widget
|
||||
protected function getViewData(): array
|
||||
{
|
||||
return [
|
||||
'applications' => $this->loadApplications(),
|
||||
'composes' => $this->loadComposes(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function loadApplications(): array
|
||||
protected function loadComposes(): array
|
||||
{
|
||||
$client = app(DokployClient::class);
|
||||
$applicationMap = config('dokploy.applications', []);
|
||||
$composeMap = config('dokploy.composes', []);
|
||||
$results = [];
|
||||
|
||||
foreach ($applicationMap as $label => $applicationId) {
|
||||
foreach ($composeMap as $label => $composeId) {
|
||||
try {
|
||||
$status = $client->applicationStatus($applicationId);
|
||||
$deployments = $client->recentDeployments($applicationId, 1);
|
||||
$application = Arr::get($status, 'application', []);
|
||||
$monitoring = Arr::get($status, 'monitoring', []);
|
||||
$status = $client->composeStatus($composeId);
|
||||
$deployments = $client->composeDeployments($composeId, 1);
|
||||
$compose = Arr::get($status, 'compose', []);
|
||||
$services = $this->formatServices(Arr::get($status, 'services', []));
|
||||
|
||||
$results[] = [
|
||||
'label' => ucfirst($label),
|
||||
'application_id' => $applicationId,
|
||||
'app_name' => Arr::get($application, 'appName') ?? Arr::get($application, 'name'),
|
||||
'status' => Arr::get($application, 'applicationStatus', 'unknown'),
|
||||
'cpu' => $this->extractMetric($monitoring, [
|
||||
'metrics.cpuPercent',
|
||||
'metrics.cpu_percent',
|
||||
'cpuPercent',
|
||||
'cpu_percent',
|
||||
]),
|
||||
'memory' => $this->extractMetric($monitoring, [
|
||||
'metrics.memoryPercent',
|
||||
'metrics.memory_percent',
|
||||
'memoryPercent',
|
||||
'memory_percent',
|
||||
]),
|
||||
'compose_id' => $composeId,
|
||||
'name' => Arr::get($compose, 'name') ?? Arr::get($compose, 'appName') ?? $composeId,
|
||||
'status' => Arr::get($compose, 'composeStatus', 'unknown'),
|
||||
'services' => $services,
|
||||
'last_deploy' => Arr::get($deployments, '0.createdAt')
|
||||
?? Arr::get($deployments, '0.created_at')
|
||||
?? Arr::get($application, 'updatedAt')
|
||||
?? Arr::get($application, 'lastDeploymentAt'),
|
||||
?? Arr::get($compose, 'updatedAt')
|
||||
?? Arr::get($compose, 'lastDeploymentAt'),
|
||||
];
|
||||
} catch (\Throwable $exception) {
|
||||
$results[] = [
|
||||
'label' => ucfirst($label),
|
||||
'application_id' => $applicationId,
|
||||
'compose_id' => $composeId,
|
||||
'status' => 'unreachable',
|
||||
'error' => $exception->getMessage(),
|
||||
];
|
||||
@@ -68,9 +57,9 @@ class DokployPlatformHealth extends Widget
|
||||
return [
|
||||
[
|
||||
'label' => 'Dokploy',
|
||||
'application_id' => '-',
|
||||
'compose_id' => '-',
|
||||
'status' => 'unconfigured',
|
||||
'error' => 'Set DOKPLOY_APPLICATION_IDS in .env to enable monitoring.',
|
||||
'error' => 'Set DOKPLOY_COMPOSE_IDS in .env to enable monitoring.',
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -78,14 +67,17 @@ class DokployPlatformHealth extends Widget
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function extractMetric(array $source, array $candidates): mixed
|
||||
protected function formatServices(array $services): array
|
||||
{
|
||||
foreach ($candidates as $key) {
|
||||
if (Arr::has($source, $key)) {
|
||||
return Arr::get($source, $key);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return collect($services)
|
||||
->map(function ($service) {
|
||||
return [
|
||||
'name' => Arr::get($service, 'serviceName') ?? Arr::get($service, 'name') ?? Arr::get($service, 'containerName'),
|
||||
'status' => Arr::get($service, 'status') ?? Arr::get($service, 'state') ?? Arr::get($service, 'composeStatus', 'unknown'),
|
||||
];
|
||||
})
|
||||
->filter(fn ($service) => filled($service['name']))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user