diff --git a/frontend/classes/class.container.php b/frontend/classes/class.container.php index a5d80d4..9b10265 100644 --- a/frontend/classes/class.container.php +++ b/frontend/classes/class.container.php @@ -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(); diff --git a/frontend/module.vps.overview.php b/frontend/module.vps.overview.php index 554fbbf..36ebbea 100644 --- a/frontend/module.vps.overview.php +++ b/frontend/module.vps.overview.php @@ -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" )); ?> diff --git a/frontend/templates/vps.overview.tpl b/frontend/templates/vps.overview.tpl index 8603b0d..1103a51 100644 --- a/frontend/templates/vps.overview.tpl +++ b/frontend/templates/vps.overview.tpl @@ -12,8 +12,8 @@