2024-06-18 14:42:42 +00: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 14:43:18 +00:00
|
|
|
|
2024-06-18 14:42:42 +00:00
|
|
|
public $interval = 5;
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.charts.server-memory');
|
|
|
|
}
|
2024-06-18 14:43:18 +00:00
|
|
|
|
2024-06-18 14:42:42 +00: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 14:43:18 +00:00
|
|
|
|
|
|
|
public function setInterval()
|
|
|
|
{
|
2024-06-18 14:42:42 +00:00
|
|
|
$this->loadData();
|
|
|
|
}
|
|
|
|
}
|