2014-06-18 04:11:11 -04:00
|
|
|
<?php
|
|
|
|
|
2014-06-18 04:15:18 -04:00
|
|
|
if (!($load_tmp = shell_exec('cat /proc/loadavg | awk \'{print $1","$2","$3}\'')))
|
2014-06-18 04:11:11 -04:00
|
|
|
{
|
|
|
|
$load = array(0, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-18 04:15:18 -04:00
|
|
|
// Number of cores
|
|
|
|
$cores = (int)shell_exec('grep -c ^processor /proc/cpuinfo');
|
|
|
|
|
2014-06-18 04:11:11 -04:00
|
|
|
$load_exp = explode(',', $load_tmp);
|
|
|
|
|
|
|
|
$load = array_map(
|
2014-06-18 04:15:18 -04:00
|
|
|
function ($value, $cores) {
|
|
|
|
$v = (int)($value * 100 / $cores);
|
2014-06-18 04:11:11 -04:00
|
|
|
if ($v > 100)
|
|
|
|
$v = 100;
|
|
|
|
return $v;
|
|
|
|
},
|
2014-06-18 04:15:18 -04:00
|
|
|
$load_exp,
|
|
|
|
array_fill(0, 3, $cores)
|
2014-06-18 04:11:11 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$datas = $load;
|
|
|
|
|
|
|
|
echo json_encode($datas);
|