ezservermonitor-web/libs/load_average.php

30 lines
567 B
PHP
Raw Normal View History

2014-06-18 04:11:11 -04:00
<?php
require '../autoload.php';
2014-06-18 04:11:11 -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
{
// Number of cores
$cores = Misc::getCpuCoresNumber();
2014-06-18 04:11:11 -04:00
$load_exp = explode(',', $load_tmp);
$load = array_map(
function ($value, $cores) {
$v = (int)((float)$value * 100 / $cores);
2014-06-18 04:11:11 -04:00
if ($v > 100)
$v = 100;
return $v;
},
$load_exp,
array_fill(0, 3, $cores)
2014-06-18 04:11:11 -04:00
);
}
$datas = $load;
echo json_encode($datas);