fix: charts
This commit is contained in:
parent
a43de75b42
commit
36f251e710
@ -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 @@ public function mount()
|
||||
$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 @@ public function loadData()
|
||||
|
||||
public function setInterval()
|
||||
{
|
||||
if ($this->interval <= 10) {
|
||||
$this->poll = true;
|
||||
}
|
||||
$this->loadData();
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ public function loadData()
|
||||
|
||||
public function setInterval()
|
||||
{
|
||||
if ($this->interval <= 10) {
|
||||
$this->poll = true;
|
||||
}
|
||||
$this->loadData();
|
||||
}
|
||||
}
|
||||
|
@ -498,28 +498,11 @@ public function getCpuMetrics(int $mins = 5)
|
||||
$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 @@ public function getMemoryMetrics(int $mins = 5)
|
||||
$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();
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
<div wire:poll.5000ms='loadData'>
|
||||
<div @if ($poll) wire:poll.5000ms='pollData' @endif>
|
||||
<h3>CPU</h3>
|
||||
<x-forms.select label="Interval" wire:change="setInterval" id="interval">
|
||||
<option value="5">5 minutes</option>
|
||||
<option value="10">10 minutes</option>
|
||||
<option value="5">5 minutes (live)</option>
|
||||
<option value="10">10 minutes (live)</option>
|
||||
<option value="30">30 minutes</option>
|
||||
<option value="60">1 hour</option>
|
||||
<option value="720">12 hours</option>
|
||||
|
@ -1,8 +1,8 @@
|
||||
<div wire:poll.5000ms='loadData'>
|
||||
<div @if ($poll) wire:poll.5000ms='pollData' @endif>
|
||||
<h3>Memory</h3>
|
||||
<x-forms.select label="Interval" wire:change="setInterval" id="interval">
|
||||
<option value="5">5 minutes</option>
|
||||
<option value="10">10 minutes</option>
|
||||
<option value="5">5 minutes (live)</option>
|
||||
<option value="10">10 minutes (live)</option>
|
||||
<option value="30">30 minutes</option>
|
||||
<option value="60">1 hour</option>
|
||||
<option value="720">12 hours</option>
|
||||
|
Loading…
Reference in New Issue
Block a user