ezservermonitor-web/libs/swap.php

34 lines
677 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
// Free
if (!($free = shell_exec('grep SwapFree /proc/meminfo | awk \'{print $2}\'')))
{
$free = 0;
}
$free = (int)$free;
2014-06-18 04:11:11 -04:00
// Total
if (!($total = shell_exec('grep SwapTotal /proc/meminfo | awk \'{print $2}\'')))
{
$total = 0;
}
$total = (int)$total;
2014-06-18 04:11:11 -04:00
// Used
$used = $total - $free;
// Percent used
$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);