Refactor metrics retrieval and update chart visualization

This commit is contained in:
Andras Bacsai 2024-05-09 15:44:32 +02:00
parent 1bb0d54dce
commit 1f5f51e3e5
2 changed files with 8 additions and 6 deletions

View File

@ -483,14 +483,12 @@ public function checkSentinel()
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);
$from = now()->subMinutes(5)->toIso8601ZuluString();
$cpu = instant_remote_process(["docker exec coolify-sentinel sh -c 'curl http://localhost:8888/api/cpu/history?from=$from'"], $this, false);
$cpu = str($cpu)->explode("\n")->skip(1)->all();
$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();

View File

@ -93,6 +93,7 @@
return '#D9534F'
}
}],
xaxis: {
type: 'datetime'
},
@ -107,9 +108,12 @@
enabled: true
},
chart: {
stroke: {
curve: 'smooth',
},
height: 500,
width: "100%",
type: "area",
type: "line",
toolbar: {
show: true
},