2014-06-18 04:11:11 -04:00
|
|
|
<?php
|
2015-07-07 09:57:41 -04:00
|
|
|
require '../autoload.php';
|
2014-06-18 04:11:11 -04:00
|
|
|
|
2015-02-05 12:29:16 -05:00
|
|
|
$free = 0;
|
|
|
|
|
|
|
|
if (shell_exec('cat /proc/meminfo'))
|
2014-06-18 04:11:11 -04:00
|
|
|
{
|
2015-02-05 12:29:16 -05:00
|
|
|
$free = shell_exec('grep MemFree /proc/meminfo | awk \'{print $2}\'');
|
|
|
|
$buffers = shell_exec('grep Buffers /proc/meminfo | awk \'{print $2}\'');
|
|
|
|
$cached = shell_exec('grep Cached /proc/meminfo | awk \'{print $2}\'');
|
|
|
|
|
|
|
|
$free = (int)$free + (int)$buffers + (int)$cached;
|
2014-06-18 04:11:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Total
|
2015-02-05 12:29:16 -05:00
|
|
|
if (!($total = shell_exec('grep MemTotal /proc/meminfo | awk \'{print $2}\'')))
|
2014-06-18 04:11:11 -04:00
|
|
|
{
|
|
|
|
$total = 0;
|
|
|
|
}
|
2017-11-02 15:54:43 -04:00
|
|
|
$total = (int)$total;
|
2014-06-18 04:11:11 -04:00
|
|
|
|
|
|
|
// Used
|
|
|
|
$used = $total - $free;
|
|
|
|
|
|
|
|
// Percent used
|
2015-07-07 09:57:41 -04:00
|
|
|
$percent_used = 0;
|
|
|
|
if ($total > 0)
|
|
|
|
$percent_used = 100 - (round($free / $total * 100));
|
2014-06-18 04:11:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
$datas = array(
|
|
|
|
'used' => Misc::getSize($used * 1024),
|
|
|
|
'free' => Misc::getSize($free * 1024),
|
|
|
|
'total' => Misc::getSize($total * 1024),
|
|
|
|
'percent_used' => $percent_used,
|
|
|
|
);
|
|
|
|
|
|
|
|
echo json_encode($datas);
|