RAM statistics on VPS overview

feature/node-rewrite
Sven Slootweg 13 years ago
parent c9dbc8eb77
commit 23a7d117c0

@ -61,6 +61,9 @@ class Container extends CPHPDatabaseRecordClass
case "sRamUsed":
return $this->GetRamUsed();
break;
case "sRamTotal":
return $this->GetRamTotal();
break;
case "sDiskUsed":
return $this->GetDiskUsed();
break;
@ -130,6 +133,49 @@ class Container extends CPHPDatabaseRecordClass
}
}
public function GetRamUsed()
{
$ram = $this->GetRam();
return $ram['used'];
}
public function GetRamTotal()
{
$ram = $this->GetRam();
return $ram['total'];
}
public function GetRam()
{
$result = $this->RunCommandCached("free -m", true);
$lines = explode("\n", $result->stdout);
array_shift($lines);
$total_free = 0;
$total_used = 0;
$total_total = 0;
foreach($lines as $line)
{
$line = trim($line);
$values = split_whitespace($line);
if(trim($values[0]) == "Mem:")
{
$total_total = $values[1];
$total_used = $values[2];
$total_free = $values[3];
}
}
return array(
'free' => $total_free,
'used' => $total_used,
'total' => $total_total
);
}
public function GetDiskUsed()
{
$disk = $this->GetDisk();

@ -42,7 +42,11 @@ $sPageContents = Templater::InlineRender("vps.overview", $locale->strings, array
'disk-used' => number_format($sContainer->sDiskUsed / 1024, 2),
'disk-total' => number_format($sContainer->sDiskTotal / 1024, 2),
'disk-percentage' => number_format(($sContainer->sDiskUsed / $sContainer->sDiskTotal) * 100, 2),
'disk-unit' => "GB"
'disk-unit' => "GB",
'ram-used' => $sContainer->sRamUsed,
'ram-total' => $sContainer->sRamTotal,
'ram-percentage' => ($sContainer->sRamUsed / $sContainer->sRamTotal) * 100,
'ram-unit' => "MB"
));
?>

@ -12,8 +12,8 @@
<div class="quota-item">
<h3>RAM</h3>
<div class="quota-bar">
<div class="quota-bar-inner" style="width: 24%;"></div>
<div class="quota-bar-label">241/1024MB</div>
<div class="quota-bar-inner" style="width: <%?ram-percentage>%;"></div>
<div class="quota-bar-label"><%?ram-used>/<%?ram-total><%?ram-unit></div>
</div>
</div>
<div class="quota-item last">

Loading…
Cancel
Save