fix: charts
This commit is contained in:
@@ -15,7 +15,9 @@ class ServerCpu extends Component
|
|||||||
|
|
||||||
public $categories;
|
public $categories;
|
||||||
|
|
||||||
public $interval = 5;
|
public int $interval = 5;
|
||||||
|
|
||||||
|
public bool $poll = true;
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
@@ -27,6 +29,16 @@ class ServerCpu extends Component
|
|||||||
$this->loadData();
|
$this->loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pollData()
|
||||||
|
{
|
||||||
|
if ($this->poll || $this->interval <= 10) {
|
||||||
|
$this->loadData();
|
||||||
|
if ($this->interval > 10) {
|
||||||
|
$this->poll = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function loadData()
|
public function loadData()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -44,6 +56,9 @@ class ServerCpu extends Component
|
|||||||
|
|
||||||
public function setInterval()
|
public function setInterval()
|
||||||
{
|
{
|
||||||
|
if ($this->interval <= 10) {
|
||||||
|
$this->poll = true;
|
||||||
|
}
|
||||||
$this->loadData();
|
$this->loadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,25 @@ class ServerMemory extends Component
|
|||||||
|
|
||||||
public $categories;
|
public $categories;
|
||||||
|
|
||||||
public $interval = 5;
|
public int $interval = 5;
|
||||||
|
|
||||||
|
public bool $poll = true;
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.charts.server-memory');
|
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()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->loadData();
|
$this->loadData();
|
||||||
@@ -44,6 +56,9 @@ class ServerMemory extends Component
|
|||||||
|
|
||||||
public function setInterval()
|
public function setInterval()
|
||||||
{
|
{
|
||||||
|
if ($this->interval <= 10) {
|
||||||
|
$this->poll = true;
|
||||||
|
}
|
||||||
$this->loadData();
|
$this->loadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -498,28 +498,11 @@ $schema://$host {
|
|||||||
$parsedCollection = collect($cpu)->flatMap(function ($item) {
|
$parsedCollection = collect($cpu)->flatMap(function ($item) {
|
||||||
return collect(explode("\n", trim($item)))->map(function ($line) {
|
return collect(explode("\n", trim($item)))->map(function ($line) {
|
||||||
[$time, $value] = explode(',', trim($line));
|
[$time, $value] = explode(',', trim($line));
|
||||||
|
$value = number_format($value, 0);
|
||||||
|
|
||||||
return [(int) $time, (float) $value];
|
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();
|
return $parsedCollection->toArray();
|
||||||
}
|
}
|
||||||
@@ -542,28 +525,11 @@ $schema://$host {
|
|||||||
$parsedCollection = collect($memory)->flatMap(function ($item) {
|
$parsedCollection = collect($memory)->flatMap(function ($item) {
|
||||||
return collect(explode("\n", trim($item)))->map(function ($line) {
|
return collect(explode("\n", trim($item)))->map(function ($line) {
|
||||||
[$time, $used, $free, $usedPercent] = explode(',', trim($line));
|
[$time, $used, $free, $usedPercent] = explode(',', trim($line));
|
||||||
|
$usedPercent = number_format($usedPercent, 0);
|
||||||
|
|
||||||
return [(int) $time, (float) $usedPercent];
|
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();
|
return $parsedCollection->toArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<div wire:poll.5000ms='loadData'>
|
<div @if ($poll) wire:poll.5000ms='pollData' @endif>
|
||||||
<h3>CPU</h3>
|
<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</option>
|
<option value="5">5 minutes (live)</option>
|
||||||
<option value="10">10 minutes</option>
|
<option value="10">10 minutes (live)</option>
|
||||||
<option value="30">30 minutes</option>
|
<option value="30">30 minutes</option>
|
||||||
<option value="60">1 hour</option>
|
<option value="60">1 hour</option>
|
||||||
<option value="720">12 hours</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>
|
<h3>Memory</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</option>
|
<option value="5">5 minutes (live)</option>
|
||||||
<option value="10">10 minutes</option>
|
<option value="10">10 minutes (live)</option>
|
||||||
<option value="30">30 minutes</option>
|
<option value="30">30 minutes</option>
|
||||||
<option value="60">1 hour</option>
|
<option value="60">1 hour</option>
|
||||||
<option value="720">12 hours</option>
|
<option value="720">12 hours</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user