fix: charts ui
This commit is contained in:
		@@ -5,7 +5,6 @@ namespace App\Livewire\Project\Database;
 | 
				
			|||||||
use App\Models\ScheduledDatabaseBackup;
 | 
					use App\Models\ScheduledDatabaseBackup;
 | 
				
			||||||
use Illuminate\Support\Facades\Auth;
 | 
					use Illuminate\Support\Facades\Auth;
 | 
				
			||||||
use Illuminate\Support\Facades\Hash;
 | 
					use Illuminate\Support\Facades\Hash;
 | 
				
			||||||
use Livewire\Attributes\On;
 | 
					 | 
				
			||||||
use Livewire\Component;
 | 
					use Livewire\Component;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BackupExecutions extends Component
 | 
					class BackupExecutions extends Component
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,12 +34,6 @@ class Charts extends Component
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            $cpuMetrics = $this->server->getCpuMetrics($this->interval);
 | 
					            $cpuMetrics = $this->server->getCpuMetrics($this->interval);
 | 
				
			||||||
            $memoryMetrics = $this->server->getMemoryMetrics($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", [
 | 
					            $this->dispatch("refreshChartData-{$this->chartId}-cpu", [
 | 
				
			||||||
                'seriesData' => $cpuMetrics,
 | 
					                'seriesData' => $cpuMetrics,
 | 
				
			||||||
            ]);
 | 
					            ]);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1406,15 +1406,7 @@ class Application extends BaseModel
 | 
				
			|||||||
        $container_name = $this->uuid;
 | 
					        $container_name = $this->uuid;
 | 
				
			||||||
        if ($server->isMetricsEnabled()) {
 | 
					        if ($server->isMetricsEnabled()) {
 | 
				
			||||||
            $from = now()->subMinutes($mins)->toIso8601ZuluString();
 | 
					            $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')) {
 | 
					            if (str($metrics)->contains('error')) {
 | 
				
			||||||
                $error = json_decode($metrics, true);
 | 
					                $error = json_decode($metrics, true);
 | 
				
			||||||
                $error = data_get($error, 'error', 'Something is not okay, are you okay?');
 | 
					                $error = data_get($error, 'error', 'Something is not okay, are you okay?');
 | 
				
			||||||
@@ -1438,15 +1430,7 @@ class Application extends BaseModel
 | 
				
			|||||||
        $container_name = $this->uuid;
 | 
					        $container_name = $this->uuid;
 | 
				
			||||||
        if ($server->isMetricsEnabled()) {
 | 
					        if ($server->isMetricsEnabled()) {
 | 
				
			||||||
            $from = now()->subMinutes($mins)->toIso8601ZuluString();
 | 
					            $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')) {
 | 
					            if (str($metrics)->contains('error')) {
 | 
				
			||||||
                $error = json_decode($metrics, true);
 | 
					                $error = json_decode($metrics, true);
 | 
				
			||||||
                $error = data_get($error, 'error', 'Something is not okay, are you okay?');
 | 
					                $error = data_get($error, 'error', 'Something is not okay, are you okay?');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -592,15 +592,7 @@ $schema://$host {
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->isMetricsEnabled()) {
 | 
					        if ($this->isMetricsEnabled()) {
 | 
				
			||||||
            $from = now()->subMinutes($mins)->toIso8601ZuluString();
 | 
					            $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')) {
 | 
					            if (str($cpu)->contains('error')) {
 | 
				
			||||||
                $error = json_decode($cpu, true);
 | 
					                $error = json_decode($cpu, true);
 | 
				
			||||||
                $error = data_get($error, 'error', 'Something is not okay, are you okay?');
 | 
					                $error = data_get($error, 'error', 'Something is not okay, are you okay?');
 | 
				
			||||||
@@ -615,7 +607,6 @@ $schema://$host {
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return $parsedCollection;
 | 
					            return $parsedCollection;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -623,15 +614,7 @@ $schema://$host {
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->isMetricsEnabled()) {
 | 
					        if ($this->isMetricsEnabled()) {
 | 
				
			||||||
            $from = now()->subMinutes($mins)->toIso8601ZuluString();
 | 
					            $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')) {
 | 
					            if (str($memory)->contains('error')) {
 | 
				
			||||||
                $error = json_decode($memory, true);
 | 
					                $error = json_decode($memory, true);
 | 
				
			||||||
                $error = data_get($error, 'error', 'Something is not okay, are you okay?');
 | 
					                $error = data_get($error, 'error', 'Something is not okay, are you okay?');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,4 @@
 | 
				
			|||||||
<div @if ($poll) wire:poll.5000ms='pollData' @endif x-init="$wire.loadData()">
 | 
					<div @if ($poll) wire:poll.5000ms='pollData' @endif x-init="$wire.loadData()">
 | 
				
			||||||
    <h3>CPU (%)</h3>
 | 
					 | 
				
			||||||
    <x-forms.select label="Interval" wire:change="setInterval" id="interval">
 | 
					    <x-forms.select label="Interval" wire:change="setInterval" id="interval">
 | 
				
			||||||
        <option value="5">5 minutes (live)</option>
 | 
					        <option value="5">5 minutes (live)</option>
 | 
				
			||||||
        <option value="10">10 minutes (live)</option>
 | 
					        <option value="10">10 minutes (live)</option>
 | 
				
			||||||
@@ -9,6 +8,7 @@
 | 
				
			|||||||
        <option value="10080">1 week</option>
 | 
					        <option value="10080">1 week</option>
 | 
				
			||||||
        <option value="43200">30 days</option>
 | 
					        <option value="43200">30 days</option>
 | 
				
			||||||
    </x-forms.select>
 | 
					    </x-forms.select>
 | 
				
			||||||
 | 
					    <h4 class="pt-4">CPU (%)</h4>
 | 
				
			||||||
    <div wire:ignore id="{!! $chartId !!}-cpu"></div>
 | 
					    <div wire:ignore id="{!! $chartId !!}-cpu"></div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <script>
 | 
					    <script>
 | 
				
			||||||
@@ -119,7 +119,7 @@
 | 
				
			|||||||
    </script>
 | 
					    </script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <h3>Memory (%)</h3>
 | 
					        <h4>Memory (%)</h4>
 | 
				
			||||||
        <div wire:ignore id="{!! $chartId !!}-memory"></div>
 | 
					        <div wire:ignore id="{!! $chartId !!}-memory"></div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <script>
 | 
					        <script>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -60,7 +60,9 @@
 | 
				
			|||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <div x-cloak x-show="activeTab === 'metrics'" class="h-full">
 | 
					            <div x-cloak x-show="activeTab === 'metrics'" class="h-full">
 | 
				
			||||||
                @if ($server->isFunctional() && $server->isMetricsEnabled())
 | 
					                @if ($server->isFunctional() && $server->isMetricsEnabled())
 | 
				
			||||||
                    <div class="pt-10">
 | 
					                    <h2>Metrics</h2>
 | 
				
			||||||
 | 
					                    <div class="pb-4">Basic metrics for your container.</div>
 | 
				
			||||||
 | 
					                    <div>
 | 
				
			||||||
                        <livewire:server.charts :server="$server" />
 | 
					                        <livewire:server.charts :server="$server" />
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                @else
 | 
					                @else
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user