feat: init metrics
This commit is contained in:
@@ -27,7 +27,7 @@ class Logs extends Component
|
||||
public $query;
|
||||
public $status;
|
||||
public $serviceSubType;
|
||||
|
||||
public $cpu;
|
||||
public function loadContainers($server_id)
|
||||
{
|
||||
try {
|
||||
@@ -49,6 +49,14 @@ class Logs extends Component
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
public function loadMetrics()
|
||||
{
|
||||
return;
|
||||
$server = data_get($this->resource, 'destination.server');
|
||||
if ($server->isFunctional()) {
|
||||
$this->cpu = $server->getMetrics();
|
||||
}
|
||||
}
|
||||
public function mount()
|
||||
{
|
||||
try {
|
||||
@@ -95,6 +103,7 @@ class Logs extends Component
|
||||
}
|
||||
}
|
||||
$this->containers = $this->containers->sort();
|
||||
$this->loadMetrics();
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
@@ -480,6 +480,23 @@ $schema://$host {
|
||||
}
|
||||
}
|
||||
}
|
||||
public function getMetrics()
|
||||
{
|
||||
if ($this->is_metrics_enabled) {
|
||||
$cpu = instant_remote_process(["cat /data/coolify/metrics/cpu.csv | grep 'Overall' | tail -200 | awk -F, '{print $1\",\" \$NF}'"], $this, false);
|
||||
$cpu = str($cpu)->replace("%", "");
|
||||
ray($cpu);
|
||||
$parsedCollection = collect($cpu)->flatMap(function ($item) {
|
||||
return collect(explode("\n", trim($item)))->map(function ($line) {
|
||||
list($time, $value) = explode(',', trim($line));
|
||||
// convert $time from nanoseconds to milliseconds for apexcharts
|
||||
$time = (int) $time / 1000000;
|
||||
return [(int) $time, (float) $value];
|
||||
});
|
||||
})->toArray();
|
||||
return $parsedCollection;
|
||||
}
|
||||
}
|
||||
public function isServerReady(int $tries = 3)
|
||||
{
|
||||
if ($this->skipServer()) {
|
||||
|
||||
Reference in New Issue
Block a user