round($total / 1024), 'used' => round($used / 1024), 'percent' => round(($used / $total) * 100, 2) ]; } // SWAP function getSwapUsage() { $data = file('/proc/meminfo'); $info = []; foreach ($data as $line) { list($key, $value) = explode(":", $line); $info[$key] = trim(preg_replace("/[^0-9]/", "", $value)); } $total = $info['SwapTotal']; $free = $info['SwapFree']; if ($total == 0) return ['total'=>0,'used'=>0,'percent'=>0]; $used = $total - $free; return [ 'total' => round($total / 1024), 'used' => round($used / 1024), 'percent' => round(($used / $total) * 100, 2) ]; } echo json_encode([ 'cpu' => getCpuUsage(), 'ram' => getRamUsage(), 'swap' => getSwapUsage(), ]);