Files
laranode/app/Services/CPUHistoryService.php
Alex Crivion bb75e3a42b initial commit
2025-01-31 14:04:22 +02:00

35 lines
790 B
PHP

<?php
namespace App\Services;
use Illuminate\Support\Collection;
class CPUHistoryService extends SarHistory
{
public function runCommands(): array
{
return [
'sar -u -f ' . $this->sarFile,
"awk '/^[0-9]{2}:[0-9]{2}:[0-9]{2}.+[0-9]+$/ {print $1,$3,$5,$8}'"
];
}
public function parseLines(Collection $metrics): Collection
{
if (!$metrics->count()) {
return collect([]);
}
return $metrics->map(function ($stat) {
return [
'time' => $stat[0],
'user' => (float)$stat[1],
'system' => (float)$stat[2],
'idle' => (float)$stat[3],
'total' => (float)(100.00 - $stat[3])
];
});
}
}