From b5146c0dda2fefa17fa1ded9c269ce64c40863ee Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 22 Oct 2024 11:39:38 +0200 Subject: [PATCH] fix: charts ui --- .../Project/Database/BackupExecutions.php | 1 - app/Livewire/Server/Charts.php | 6 ----- app/Models/Application.php | 20 ++-------------- app/Models/Server.php | 23 +++---------------- .../views/livewire/server/charts.blade.php | 4 ++-- .../views/livewire/server/show.blade.php | 4 +++- 6 files changed, 10 insertions(+), 48 deletions(-) diff --git a/app/Livewire/Project/Database/BackupExecutions.php b/app/Livewire/Project/Database/BackupExecutions.php index b3a739d63..b29b3995b 100644 --- a/app/Livewire/Project/Database/BackupExecutions.php +++ b/app/Livewire/Project/Database/BackupExecutions.php @@ -5,7 +5,6 @@ namespace App\Livewire\Project\Database; use App\Models\ScheduledDatabaseBackup; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; -use Livewire\Attributes\On; use Livewire\Component; class BackupExecutions extends Component diff --git a/app/Livewire/Server/Charts.php b/app/Livewire/Server/Charts.php index 09b31c0b0..20f8dd9ed 100644 --- a/app/Livewire/Server/Charts.php +++ b/app/Livewire/Server/Charts.php @@ -34,12 +34,6 @@ class Charts extends Component try { $cpuMetrics = $this->server->getCpuMetrics($this->interval); $memoryMetrics = $this->server->getMemoryMetrics($this->interval); - // $cpuMetrics = collect($cpuMetrics)->map(function ($metric) { - // return [$metric[0], $metric[1]]; - // }); - // $memoryMetrics = collect($memoryMetrics)->map(function ($metric) { - // return [$metric[0], $metric[1]]; - // }); $this->dispatch("refreshChartData-{$this->chartId}-cpu", [ 'seriesData' => $cpuMetrics, ]); diff --git a/app/Models/Application.php b/app/Models/Application.php index 846d7df4c..6ed1aaf03 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -1406,15 +1406,7 @@ class Application extends BaseModel $container_name = $this->uuid; if ($server->isMetricsEnabled()) { $from = now()->subMinutes($mins)->toIso8601ZuluString(); - if (isDev() && $server->id === 0) { - $process = Process::run("curl -H \"Authorization: Bearer {$this->settings->sentinel_token}\" http://host.docker.internal:8888/api/container/{$container_name}/cpu/history?from=$from"); - if ($process->failed()) { - throw new \Exception($process->errorOutput()); - } - $metrics = $process->output(); - } else { - $metrics = instant_remote_process(["docker exec coolify-sentinel sh -c 'curl -H \"Authorization: Bearer {$server->settings->sentinel_token}\" http://localhost:8888/api/container/{$container_name}/cpu/history?from=$from'"], $server, false); - } + $metrics = instant_remote_process(["docker exec coolify-sentinel sh -c 'curl -H \"Authorization: Bearer {$server->settings->sentinel_token}\" http://localhost:8888/api/container/{$container_name}/cpu/history?from=$from'"], $server, false); if (str($metrics)->contains('error')) { $error = json_decode($metrics, true); $error = data_get($error, 'error', 'Something is not okay, are you okay?'); @@ -1438,15 +1430,7 @@ class Application extends BaseModel $container_name = $this->uuid; if ($server->isMetricsEnabled()) { $from = now()->subMinutes($mins)->toIso8601ZuluString(); - if (isDev() && $server->id === 0) { - $process = Process::run("curl -H \"Authorization: Bearer {$this->settings->sentinel_token}\" http://host.docker.internal:8888/api/container/{$container_name}/memory/history?from=$from"); - if ($process->failed()) { - throw new \Exception($process->errorOutput()); - } - $metrics = $process->output(); - } else { - $metrics = instant_remote_process(["docker exec coolify-sentinel sh -c 'curl -H \"Authorization: Bearer {$server->settings->sentinel_token}\" http://localhost:8888/api/container/{$container_name}/memory/history?from=$from'"], $server, false); - } + $metrics = instant_remote_process(["docker exec coolify-sentinel sh -c 'curl -H \"Authorization: Bearer {$server->settings->sentinel_token}\" http://localhost:8888/api/container/{$container_name}/memory/history?from=$from'"], $server, false); if (str($metrics)->contains('error')) { $error = json_decode($metrics, true); $error = data_get($error, 'error', 'Something is not okay, are you okay?'); diff --git a/app/Models/Server.php b/app/Models/Server.php index 04380fad9..c3f8347ba 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -45,7 +45,7 @@ use Symfony\Component\Yaml\Yaml; class Server extends BaseModel { - use SchemalessAttributesTrait,SoftDeletes; + use SchemalessAttributesTrait, SoftDeletes; public static $batch_counter = 0; @@ -592,15 +592,7 @@ $schema://$host { { if ($this->isMetricsEnabled()) { $from = now()->subMinutes($mins)->toIso8601ZuluString(); - if (isDev() && $this->id === 0) { - $process = Process::run("curl -H \"Authorization: Bearer {$this->settings->sentinel_token}\" http://host.docker.internal:8888/api/cpu/history?from=$from"); - if ($process->failed()) { - throw new \Exception($process->errorOutput()); - } - $cpu = $process->output(); - } else { - $cpu = instant_remote_process(["docker exec coolify-sentinel sh -c 'curl -H \"Authorization: Bearer {$this->settings->sentinel_token}\" http://localhost:8888/api/cpu/history?from=$from'"], $this, false); - } + $cpu = instant_remote_process(["docker exec coolify-sentinel sh -c 'curl -H \"Authorization: Bearer {$this->settings->sentinel_token}\" http://localhost:8888/api/cpu/history?from=$from'"], $this, false); if (str($cpu)->contains('error')) { $error = json_decode($cpu, true); $error = data_get($error, 'error', 'Something is not okay, are you okay?'); @@ -615,7 +607,6 @@ $schema://$host { }); return $parsedCollection; - } } @@ -623,15 +614,7 @@ $schema://$host { { if ($this->isMetricsEnabled()) { $from = now()->subMinutes($mins)->toIso8601ZuluString(); - if (isDev() && $this->id === 0) { - $process = Process::run("curl -H \"Authorization: Bearer {$this->settings->sentinel_token}\" http://host.docker.internal:8888/api/memory/history?from=$from"); - if ($process->failed()) { - throw new \Exception($process->errorOutput()); - } - $memory = $process->output(); - } else { - $memory = instant_remote_process(["docker exec coolify-sentinel sh -c 'curl -H \"Authorization: Bearer {$this->settings->sentinel_token}\" http://localhost:8888/api/memory/history?from=$from'"], $this, false); - } + $memory = instant_remote_process(["docker exec coolify-sentinel sh -c 'curl -H \"Authorization: Bearer {$this->settings->sentinel_token}\" http://localhost:8888/api/memory/history?from=$from'"], $this, false); if (str($memory)->contains('error')) { $error = json_decode($memory, true); $error = data_get($error, 'error', 'Something is not okay, are you okay?'); diff --git a/resources/views/livewire/server/charts.blade.php b/resources/views/livewire/server/charts.blade.php index fb472c255..b0447fd78 100644 --- a/resources/views/livewire/server/charts.blade.php +++ b/resources/views/livewire/server/charts.blade.php @@ -1,5 +1,4 @@
-

CPU (%)

@@ -9,6 +8,7 @@ +

CPU (%)

-

Memory (%)

+

Memory (%)