diff --git a/js/script.js b/js/script.js index b04657d3..6e3f91d3 100644 --- a/js/script.js +++ b/js/script.js @@ -89,11 +89,10 @@ e.preventDefault(); }) - if (cpuload === 'N/A') { + if (cpuload === 'N/A' || numCpus === -1) { $cpuFooterInfo.text(t('serverinfo', 'CPU info not available')); $cpuLoadCanvas.addClass('hidden'); return; - } else if ($cpuLoadCanvas.hasClass('hidden')) { $cpuLoadCanvas.removeClass('hidden'); } @@ -120,7 +119,7 @@ }); } - $cpuFooterInfo.text(t('serverinfo', 'Load average: {percentage} % ({cpu}) last minute', { percentage: cpuloadPercentageFixed[0], cpu: cpuloadFixed[0] })); + $cpuFooterInfo.text(t('serverinfo', 'Load average: {percentage} % ({load}) last minute', { percentage: cpuloadPercentageFixed[0], load: cpuloadFixed[0] })); $cpuFooterInfo[0].title = t( 'serverinfo', '{lastMinutePercentage} % ({lastMinute}) last Minute\n{last5MinutesPercentage} % ({last5Minutes}) last 5 Minutes\n{last15MinutesPercentage} % ({last15Minutes}) last 15 Minutes', @@ -134,7 +133,7 @@ } ); - cpuLoadLine.append(new Date().getTime(), cpuload[0]); + cpuLoadLine.append(new Date().getTime(), cpuload[0] / numCpus * 100); } function isMemoryStat(memTotal, memFree) { diff --git a/lib/OperatingSystems/Linux.php b/lib/OperatingSystems/Linux.php index 15ed38f8..71931534 100644 --- a/lib/OperatingSystems/Linux.php +++ b/lib/OperatingSystems/Linux.php @@ -92,10 +92,7 @@ public function getCpuName(): string { $model = $matches[1][0]; - $pattern = '/processor\s+:\s(.+)/'; - - preg_match_all($pattern, $cpuinfo, $matches); - $threads = count($matches[1]); + $threads = $this->getCpuCount(); if ($threads === 1) { $data = $model . ' (1 thread)'; @@ -107,14 +104,18 @@ public function getCpuName(): string { } public function getCpuCount(): int { - $numCpu = 1; // this should be a save default + $numCpu = -1; try { - $numCpu = intval($this->executeCommand('nproc --all')); - } catch (RuntimeException) { + $cpuinfo = $this->readContent('/proc/cpuinfo'); + } catch (RuntimeException $e) { + return $numCpu; } - return $numCpu; + $pattern = '/processor\s+:\s(.+)/'; + + preg_match_all($pattern, $cpuinfo, $matches); + return count($matches[1]); } public function getTime(): string {