Added disk usage stats to VPS overview

feature/node-rewrite
Sven Slootweg 13 years ago
parent 5a7198cace
commit aeaaddd389

@ -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);

@ -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
);
}
}

@ -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"
));
?>

@ -5,8 +5,8 @@
<div class="quota-item">
<h3>Disk space</h3>
<div class="quota-bar">
<div class="quota-bar-inner" style="width: 55%;"></div>
<div class="quota-bar-label">55/100GB</div>
<div class="quota-bar-inner" style="width: <%?disk-percentage>%;"></div>
<div class="quota-bar-label"><%?disk-used>/<%?disk-total><%?disk-unit></div>
</div>
</div>
<div class="quota-item">

Loading…
Cancel
Save