Bandwidth accounting

feature/node-rewrite
Sven Slootweg 13 years ago
parent 96b2f27dee
commit bedcf7e8b0

@ -33,7 +33,11 @@ class Container extends CPHPDatabaseRecordClass
'GuaranteedRam' => "GuaranteedRam",
'BurstableRam' => "BurstableRam",
'CpuCount' => "CpuCount",
'Status' => "Status"
'Status' => "Status",
'IncomingTrafficUsed' => "IncomingTrafficUsed",
'IncomingTrafficLast' => "IncomingTrafficLast",
'OutgoingTrafficUsed' => "OutgoingTrafficUsed",
'OutgoingTrafficLast' => "OutgoingTrafficLast"
),
'node' => array(
'Node' => "NodeId"
@ -244,6 +248,44 @@ class Container extends CPHPDatabaseRecordClass
}
}
public function UpdateTraffic()
{
$result = $this->sNode->ssh->RunCommand("vzctl exec {$this->sInternalId} cat /proc/net/dev | grep venet0", false);
if($result->returncode == 0)
{
$lines = split_lines($result->stdout);
$values = split_whitespace($lines[0]);
$uIncoming = $values[1];
$uOutgoing = $values[9];
if($uIncoming < (int)$this->sIncomingTrafficLast || $uOutgoing < (int)$this->sOutgoingTrafficLast)
{
// the counter has reset (wrap-around, reboot, etc.)
$uNewIncoming = $uIncoming;
$uNewOutgoing = $uOutgoing;
}
else
{
$uNewIncoming = $uIncoming - $this->sIncomingTrafficLast;
$uNewOutgoing = $uOutgoing - $this->sOutgoingTrafficLast;
}
$this->uIncomingTrafficUsed = $this->sIncomingTrafficUsed + $uNewIncoming;
$this->uOutgoingTrafficUsed = $this->sOutgoingTrafficUsed + $uNewOutgoing;
$this->uIncomingTrafficLast = $uIncoming;
$this->uOutgoingTrafficLast = $uOutgoing;
$this->InsertIntoDatabase();
}
else
{
throw new ContainerTrafficRetrieveException($result->stderr, $result->returncode, $this->sInternalId);
}
}
public function EnableTunTap()
{
// TODO: Finish EnableTunTap function, check whether tun module is available on host

@ -43,4 +43,5 @@ class ContainerStartException extends ContainerException {}
class ContainerStopException extends ContainerException {}
class ContainerIpAddException extends ContainerException {}
class ContainerIpRemoveException extends ContainerException {}
class ContainerTrafficRetrieveException extends ContainerException {}
?>

@ -17,11 +17,7 @@ elseif($_GET['action'] == "stop")
}
elseif($_GET['action'] == "bw")
{
$result = $sContainer->sNode->ssh->RunCommand("vzctl exec {$sContainer->sInternalId} cat /proc/net/dev | grep venet0", false);
$lines = split_lines($result->stdout);
$values = split_whitespace($lines[0]);
pretty_dump($values);
$sContainer->UpdateTraffic();
}
elseif($_GET['action'] == "ip")
{

Loading…
Cancel
Save