diff --git a/js/script.js b/js/script.js index 08dfa6e7..eba23de2 100644 --- a/js/script.js +++ b/js/script.js @@ -52,6 +52,14 @@ }); function updateCPUStatistics (cpuload) { + if (cpuload === 'N/A') { + $('#cpuFooterInfo').text(t('serverinfo', 'CPU info not available')); + $('#cpuloadcanvas').addClass('hidden'); + return; + + } else if ($("#cpuloadcanvas").hasClass('hidden')) { + $("#cpuloadcanvas").removeClass('hidden'); + } var cpu1 = cpuload[0], cpu2 = cpuload[1], @@ -79,6 +87,9 @@ $('#memFooterInfo').text(t('serverinfo', 'Memory info not available')); $('#memorycanvas').addClass('hidden'); return; + + } else if ($("#memorycanvas").hasClass('hidden')) { + $("#memorycanvas").removeClass('hidden'); } var memTotalBytes = memTotal * 1024, diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index dd483a51..30f50f19 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -44,6 +44,7 @@ public function __construct(IConfig $config) { } public function getSystemStatistics() { + $processorUsage = $this->getProcessorUsage(); $memoryUsage = $this->getMemoryUsage(); return [ 'version' => $this->config->getSystemValue('version'), @@ -56,7 +57,7 @@ public function getSystemStatistics() { 'memcache.locking' => $this->config->getSystemValue('memcache.locking', 'none'), 'debug' => $this->config->getSystemValue('debug', false) ? 'yes' : 'no', 'freespace' => $this->view->free_space(), - 'cpuload' => sys_getloadavg(), + 'cpuload' => $processorUsage['loadavg'], 'mem_total' => $memoryUsage['mem_total'], 'mem_free' => $memoryUsage['mem_free'] ]; @@ -94,4 +95,25 @@ protected function getMemoryUsage() { ]; } + /** + * Get current CPU load average + * + * @return array load average with three values, 1/5/15 minutes average. + */ + protected function getProcessorUsage() { + // get current system load average. + $loadavg = sys_getloadavg(); + + // check if we got any values back. + if (!(is_array($loadavg) && count($loadavg) === 3)) { + // either no array or too few array keys. + // returning back zeroes to prevent any errors on JS side. + $loadavg = 'N/A'; + } + + return [ + 'loadavg' => $loadavg + ]; + } + }