diff options
author | Patrik Kernstock <info@pkern.at> | 2017-06-01 13:54:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-01 13:54:02 +0300 |
commit | 6f1b0f223fcde837c0ebcad5b4a3260db6ddc1ac (patch) | |
tree | 5972a44ee12f1f9bcd8a5f530268e168af850d35 /lib | |
parent | eb40aafa79a9e4a5b2d47ffed62033056de646fd (diff) |
Checking for valid CPU average values
Signed-off-by: Patrik Kernstock <info@pkern.at>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/SystemStatistics.php | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index dd483a5..1ca6a4b 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -44,6 +44,7 @@ class SystemStatistics { } public function getSystemStatistics() { + $processorUsage = $this->getProcessorUsage(); $memoryUsage = $this->getMemoryUsage(); return [ 'version' => $this->config->getSystemValue('version'), @@ -56,7 +57,7 @@ class SystemStatistics { '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 @@ class SystemStatistics { ]; } + /** + * 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 = [0, 0, 0]; + } + + return [ + 'loadavg' => $loadavg + ]; + } + } |