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
This commit is contained in:
ShevAbam 2015-01-16 18:14:07 +01:00
parent c3ec82dd6f
commit 3ed4c1d633
6 changed files with 42 additions and 26 deletions

View File

@ -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>';

View File

@ -2,9 +2,9 @@
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');
@ -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
*/

View File

@ -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;

View File

@ -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,
);
}

View File

@ -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);

View File

@ -15,6 +15,7 @@ if (!($os = shell_exec('/usr/bin/lsb_release -ds')))
}
}
}
$os = trim($os, '"');
// Kernel
if (!($kernel = shell_exec('/bin/uname -r')))