Skip to content

Commit

Permalink
fix: Graphs data normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Jun 20, 2023
1 parent d9781d4 commit 81d20ad
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\LimanRequest;
use App\Models\Server;
use App\Models\Token;
use App\System\Command;
use App\User;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Routing\ResponseFactory;
Expand Down Expand Up @@ -79,6 +80,7 @@ public function all()
*/
public function getLimanStats()
{
$cores = str_replace("cpu cores\t: ", "", trim(explode("\n", Command::runLiman("cat /proc/cpuinfo | grep 'cpu cores'"))[0]));
$cpuUsage = shell_exec(
"ps -eo %cpu --no-headers | grep -v 0.0 | awk '{s+=$1} END {print s/NR*10}'"
);
Expand All @@ -95,10 +97,12 @@ public function getLimanStats()
$secondDown = $this->calculateNetworkBytes();
$secondUp = $this->calculateNetworkBytes(false);

$totalCpu = round($cpuUsage / $cores, 2);

return response([
'cpu' => $cpuUsage,
'ram' => $ramUsage,
'io' => round($ioPercent, 2),
'cpu' => $totalCpu > 100 ? 100 : $totalCpu,
'ram' => $ramUsage > 100 ? 100 : $ramUsage,
'io' => $ioPercent > 100 ? 100 : round($ioPercent, 2),
'network' => [
'download' => round(($secondDown - $firstDown) / 1024 / 2, 2),
'upload' => round(($secondUp - $firstUp) / 1024 / 2, 2),
Expand Down

0 comments on commit 81d20ad

Please sign in to comment.