diff --git a/app/Livewire/Charts/ServerCpu.php b/app/Livewire/Charts/ServerCpu.php index 454f59193..50a7e115e 100644 --- a/app/Livewire/Charts/ServerCpu.php +++ b/app/Livewire/Charts/ServerCpu.php @@ -15,7 +15,9 @@ class ServerCpu extends Component public $categories; - public $interval = 5; + public int $interval = 5; + + public bool $poll = true; public function render() { @@ -27,6 +29,16 @@ class ServerCpu extends Component $this->loadData(); } + public function pollData() + { + if ($this->poll || $this->interval <= 10) { + $this->loadData(); + if ($this->interval > 10) { + $this->poll = false; + } + } + } + public function loadData() { try { @@ -44,6 +56,9 @@ class ServerCpu extends Component public function setInterval() { + if ($this->interval <= 10) { + $this->poll = true; + } $this->loadData(); } } diff --git a/app/Livewire/Charts/ServerMemory.php b/app/Livewire/Charts/ServerMemory.php index f3f992e97..15a2345f5 100644 --- a/app/Livewire/Charts/ServerMemory.php +++ b/app/Livewire/Charts/ServerMemory.php @@ -15,13 +15,25 @@ class ServerMemory extends Component public $categories; - public $interval = 5; + public int $interval = 5; + + public bool $poll = true; public function render() { return view('livewire.charts.server-memory'); } + public function pollData() + { + if ($this->poll || $this->interval <= 10) { + $this->loadData(); + if ($this->interval > 10) { + $this->poll = false; + } + } + } + public function mount() { $this->loadData(); @@ -44,6 +56,9 @@ class ServerMemory extends Component public function setInterval() { + if ($this->interval <= 10) { + $this->poll = true; + } $this->loadData(); } } diff --git a/app/Models/Server.php b/app/Models/Server.php index 1dedf8045..3d40042bb 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -498,28 +498,11 @@ $schema://$host { $parsedCollection = collect($cpu)->flatMap(function ($item) { return collect(explode("\n", trim($item)))->map(function ($line) { [$time, $value] = explode(',', trim($line)); + $value = number_format($value, 0); return [(int) $time, (float) $value]; }); }); - if ($mins === 30 || $mins === 60) { - $parsedCollection = $parsedCollection->filter(function ($item, $key) { - return $key % 5 === 0; - }); - $parsedCollection = $parsedCollection->values(); - } - if ($mins === 720) { - $parsedCollection = $parsedCollection->filter(function ($item, $key) { - return $key % 10 === 0; - }); - $parsedCollection = $parsedCollection->values(); - } - if ($mins === 10080) { - $parsedCollection = $parsedCollection->filter(function ($item, $key) { - return $key % 20 === 0; - }); - $parsedCollection = $parsedCollection->values(); - } return $parsedCollection->toArray(); } @@ -542,28 +525,11 @@ $schema://$host { $parsedCollection = collect($memory)->flatMap(function ($item) { return collect(explode("\n", trim($item)))->map(function ($line) { [$time, $used, $free, $usedPercent] = explode(',', trim($line)); + $usedPercent = number_format($usedPercent, 0); return [(int) $time, (float) $usedPercent]; }); }); - if ($mins === 30 || $mins === 60) { - $parsedCollection = $parsedCollection->filter(function ($item, $key) { - return $key % 5 === 0; - }); - $parsedCollection = $parsedCollection->values(); - } - if ($mins === 720) { - $parsedCollection = $parsedCollection->filter(function ($item, $key) { - return $key % 10 === 0; - }); - $parsedCollection = $parsedCollection->values(); - } - if ($mins === 10080) { - $parsedCollection = $parsedCollection->filter(function ($item, $key) { - return $key % 20 === 0; - }); - $parsedCollection = $parsedCollection->values(); - } return $parsedCollection->toArray(); } diff --git a/resources/views/livewire/charts/server-cpu.blade.php b/resources/views/livewire/charts/server-cpu.blade.php index ff85f94f1..a6eefdf15 100644 --- a/resources/views/livewire/charts/server-cpu.blade.php +++ b/resources/views/livewire/charts/server-cpu.blade.php @@ -1,8 +1,8 @@ -