From 3ed4c1d633f3ddfc50d921c5d5c19ebf7cf640c4 Mon Sep 17 00:00:00 2001 From: ShevAbam Date: Fri, 16 Jan 2015 18:14:07 +0100 Subject: [PATCH] CPU : changes on retrieving CPU information Load Average and CPU : fix on recovery the number of CPU cores Last login : the datas are retrieved differently --- js/esm.js | 1 - libs/Utils/Misc.class.php | 32 ++++++++++++++++++++++++++------ libs/cpu.php | 25 +++++++++++-------------- libs/last_login.php | 6 ++---- libs/load_average.php | 3 ++- libs/system.php | 1 + 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/js/esm.js b/js/esm.js index 6fad950..40ed93b 100644 --- a/js/esm.js +++ b/js/esm.js @@ -145,7 +145,6 @@ esm.getLast_login = function() { var html = ''; html += ''; html += ''+data[line].user+''; - html += ''+data[line].host+''; html += ''+data[line].date+''; html += ''; diff --git a/libs/Utils/Misc.class.php b/libs/Utils/Misc.class.php index ae4b6d1..e2fe7cb 100644 --- a/libs/Utils/Misc.class.php +++ b/libs/Utils/Misc.class.php @@ -2,24 +2,24 @@ class Misc { - /** - * Returns human size - */ + /** + * Returns human size + */ public static function getSize($filesize, $precision = 2) { $units = array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'); - + foreach ($units as $idUnit => $unit) { if ($filesize > 1024) - $filesize /= 1024; + $filesize /= 1024; else break; } return round($filesize, $precision).' '.$units[$idUnit].'B'; } - + /** * Returns hostname @@ -30,6 +30,26 @@ class Misc } + /** + * Returns CPU cores number + */ + public static function getCpuCoresNumber() + { + if (!($num_cores = shell_exec('/bin/grep -c ^processor /proc/cpuinfo'))) + { + if (!($num_cores = trim(shell_exec('/usr/bin/nproc')))) + { + $num_cores = 1; + } + } + + if ((int)$num_cores <= 0) + $num_cores = 1; + + return (int)$num_cores; + } + + /** * Returns server IP */ diff --git a/libs/cpu.php b/libs/cpu.php index e2743f9..73a5409 100644 --- a/libs/cpu.php +++ b/libs/cpu.php @@ -1,21 +1,17 @@ 'N.A', - 'host' => 'N.A', 'date' => 'N.A', ); } @@ -19,11 +18,10 @@ else for ($i = 1; $i < count($users) && $i <= $max; $i++) { - list($user, $host, $date) = explode(',', $users[$i]); + list($user, $date) = explode(';', $users[$i]); $datas[] = array( 'user' => $user, - 'host' => $host, 'date' => $date, ); } diff --git a/libs/load_average.php b/libs/load_average.php index 6251c0e..2e1947d 100644 --- a/libs/load_average.php +++ b/libs/load_average.php @@ -1,4 +1,5 @@