coolify/app/Livewire/Charts/ServerMemory.php

50 lines
979 B
PHP
Raw Normal View History

2024-06-18 16:42:42 +02:00
<?php
namespace App\Livewire\Charts;
use App\Models\Server;
use Livewire\Component;
class ServerMemory extends Component
{
public Server $server;
public $chartId = 'server-memory';
public $data;
public $categories;
2024-06-18 16:43:18 +02:00
2024-06-18 16:42:42 +02:00
public $interval = 5;
public function render()
{
return view('livewire.charts.server-memory');
}
2024-06-18 16:43:18 +02:00
2024-06-18 16:42:42 +02:00
public function mount()
{
$this->loadData();
}
public function loadData()
{
try {
$metrics = $this->server->getMemoryMetrics($this->interval);
$metrics = collect($metrics)->map(function ($metric) {
return [$metric[0], $metric[1]];
});
$this->dispatch("refreshChartData-{$this->chartId}", [
'seriesData' => $metrics,
]);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
2024-06-18 16:43:18 +02:00
public function setInterval()
{
2024-06-18 16:42:42 +02:00
$this->loadData();
}
}