diff --git a/frontend/classes/class.container.php b/frontend/classes/class.container.php index f8cb128..254f483 100644 --- a/frontend/classes/class.container.php +++ b/frontend/classes/class.container.php @@ -64,6 +64,9 @@ class Container extends CPHPDatabaseRecordClass case "sDiskUsed": return $this->GetDiskUsed(); break; + case "sDiskTotal": + return $this->GetDiskTotal(); + break; case "sBandwidthUsed": return $this->GetBandwidthUsed(); break; @@ -127,6 +130,48 @@ class Container extends CPHPDatabaseRecordClass } } + public function GetDiskUsed() + { + $disk = $this->GetDisk(); + return $disk['used']; + } + + public function GetDiskTotal() + { + $disk = $this->GetDisk(); + return $disk['total']; + } + + public function GetDisk() + { + $result = $this->sNode->ssh->RunCommandCached("vzctl exec {$this->sInternalId} df -l -x tmpfs", true); + $lines = explode("\n", $result->stdout); + array_shift($lines); + + $total_free = 0; + $total_used = 0; + $total_total = 0; + + foreach($lines as $disk) + { + $disk = trim($disk); + + if(!empty($disk)) + { + $values = split_whitespace($disk); + $total_free += (int)$values[3] / 1024; + $total_used += (int)$values[2] / 1024; + $total_total += ((int)$values[2] + (int)$values[3]) / 1024; + } + } + + return array( + 'free' => $total_free, + 'used' => $total_used, + 'total' => $total_total + ); + } + public function Deploy($conf = array()) { $sRootPassword = random_string(20); diff --git a/frontend/classes/class.node.php b/frontend/classes/class.node.php index 34ea79f..bb3c901 100644 --- a/frontend/classes/class.node.php +++ b/frontend/classes/class.node.php @@ -104,6 +104,7 @@ class Node extends CPHPDatabaseRecordClass $total_free = 0; $total_used = 0; + $total_total = 0; foreach($lines as $disk) { @@ -114,12 +115,14 @@ class Node extends CPHPDatabaseRecordClass $values = split_whitespace($disk); $total_free += (int)$values[3] / 1024; $total_used += (int)$values[2] / 1024; + $total_total += ((int)$values[2] + (int)$values[3]) / 1024; } } return array( 'free' => $total_free, - 'used' => $total_used + 'used' => $total_used, + 'total' => $total_total ); } } diff --git a/frontend/module.vps.overview.php b/frontend/module.vps.overview.php index 4ac245e..554fbbf 100644 --- a/frontend/module.vps.overview.php +++ b/frontend/module.vps.overview.php @@ -38,6 +38,11 @@ $sPageContents = Templater::InlineRender("vps.overview", $locale->strings, array 'disk-space' => "{$sContainer->sDiskSpace}MB", 'total-traffic-limit' => "{$sContainer->sTotalTrafficLimit} bytes", 'bandwidth-limit' => "100mbit", - 'status' => $sContainer->sStatusText + 'status' => $sContainer->sStatusText, + '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" + )); ?> diff --git a/frontend/templates/vps.overview.tpl b/frontend/templates/vps.overview.tpl index ccfc750..8603b0d 100644 --- a/frontend/templates/vps.overview.tpl +++ b/frontend/templates/vps.overview.tpl @@ -5,8 +5,8 @@