1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/linuxdash_ynh.git synced 2024-09-03 19:36:07 +02:00
linuxdash_ynh/sources/sh/loadavg.php

22 lines
561 B
PHP
Raw Normal View History

2014-06-02 13:38:03 +02:00
<?php
exec('/bin/grep -c ^processor /proc/cpuinfo', $resultNumberOfCores);
$numberOfCores = $resultNumberOfCores[0];
exec(
'/bin/cat /proc/loadavg | /usr/bin/awk \'{print $1","$2","$3}\'',
$resultLoadAvg
);
$loadAvg = explode(',', $resultLoadAvg[0]);
header('Content-Type: application/json; charset=UTF-8');
echo json_encode(
array_map(
function ($value, $numberOfCores) {
return array($value, (int)($value * 100 / $numberOfCores));
},
$loadAvg,
array_fill(0, count($loadAvg), $numberOfCores)
)
);