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
+26 -6
View File
@@ -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
*/