15 lines
595 B
PHP
Executable File
15 lines
595 B
PHP
Executable File
<?php
|
|
header('Content-Type: application/json');
|
|
header('Cache-Control: no-cache');
|
|
$load = sys_getloadavg();
|
|
$cores = (int)trim(shell_exec('nproc'));
|
|
$cpu = $cores > 0 ? round(($load[0] / $cores) * 100, 1) : 0;
|
|
if($cpu > 100) $cpu = 100;
|
|
$memInfo = shell_exec('free -m | grep Mem');
|
|
preg_match_all('/\d+/', $memInfo, $m);
|
|
$memTotal = (int)$m[0][0];
|
|
$memUsed = (int)$m[0][1];
|
|
$ram = $memTotal > 0 ? round(($memUsed / $memTotal) * 100, 1) : 0;
|
|
$disk = (float)trim(shell_exec("df / | tail -1 | awk '{print $5}' | tr -d '%'"));
|
|
echo json_encode(['cpu'=>$cpu,'ram'=>$ram,'storage'=>round($disk,1)]);
|