summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShevAbam <shevabam@gmail.com>2015-01-16 18:14:07 +0100
committerShevAbam <shevabam@gmail.com>2015-01-16 18:14:07 +0100
commit3ed4c1d633f3ddfc50d921c5d5c19ebf7cf640c4 (patch)
treefe135c5868a41cecfae98294facb61accea76912
parentc3ec82dd6f60ac8057cc50d9bf6274738db9c02e (diff)
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
-rw-r--r--js/esm.js1
-rw-r--r--libs/Utils/Misc.class.php32
-rw-r--r--libs/cpu.php25
-rw-r--r--libs/last_login.php6
-rw-r--r--libs/load_average.php3
-rw-r--r--libs/system.php1
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 += '<tr>';
html += '<td>'+data[line].user+'</td>';
- html += '<td>'+data[line].host+'</td>';
html += '<td class="w50p">'+data[line].date+'</td>';
html += '</tr>';
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
@@ -31,6 +31,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
*/
public static function getLanIp()
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 @@
<?php
+require 'Utils/Misc.class.php';
// Number of cores
-if (!($num_cores = shell_exec('/bin/grep -c ^processor /proc/cpuinfo')))
-{
- $num_cores = 'N.A';
-}
+$num_cores = Misc::getCpuCoresNumber();
// CPU info
-if (!($cpuinfo = shell_exec('cat /proc/cpuinfo')))
-{
- $model = 'N.A';
- $frequency = 'N.A';
- $cache = 'N.A';
- $bogomips = 'N.A';
-}
-else
+$model = 'N.A';
+$frequency = 'N.A';
+$cache = 'N.A';
+$bogomips = 'N.A';
+
+if ($cpuinfo = shell_exec('cat /proc/cpuinfo'))
{
$processors = preg_split('/\s?\n\s?\n/', trim($cpuinfo));
@@ -27,15 +23,16 @@ else
{
list($key, $value) = preg_split('/\s*:\s*/', trim($detail));
- switch ($key)
+ switch (strtolower($key))
{
case 'model name':
case 'cpu model':
case 'cpu':
+ case 'processor':
$model = $value;
break;
- case 'cpu MHz':
+ case 'cpu mhz':
case 'clock':
$frequency = $value.' MHz';
break;
diff --git a/libs/last_login.php b/libs/last_login.php
index 5a8887e..e93bbf8 100644
--- a/libs/last_login.php
+++ b/libs/last_login.php
@@ -5,11 +5,10 @@ $Config = new Config();
$datas = array();
-if (!(exec('/usr/bin/lastlog --time 365 | /usr/bin/awk \'{print $1","$3","$4" "$5" "$6" "$7" "$8}\'', $users)))
+if (!(exec('/usr/bin/lastlog --time 365 | /usr/bin/awk -F\' \' \'{ print $1";"$5, $4, $8, $6}\'', $users)))
{
$datas[] = array(
'user' => '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 @@
<?php
+require 'Utils/Misc.class.php';
if (!($load_tmp = shell_exec('cat /proc/loadavg | awk \'{print $1","$2","$3}\'')))
{
@@ -7,7 +8,7 @@ if (!($load_tmp = shell_exec('cat /proc/loadavg | awk \'{print $1","$2","$3}\'')
else
{
// Number of cores
- $cores = (int)shell_exec('grep -c ^processor /proc/cpuinfo');
+ $cores = Misc::getCpuCoresNumber();
$load_exp = explode(',', $load_tmp);
diff --git a/libs/system.php b/libs/system.php
index 49232ef..7e40e3b 100644
--- a/libs/system.php
+++ b/libs/system.php
@@ -15,6 +15,7 @@ if (!($os = shell_exec('/usr/bin/lsb_release -ds')))
}
}
}
+$os = trim($os, '"');
// Kernel
if (!($kernel = shell_exec('/bin/uname -r')))