Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

Traffic accounting with iptables

158 bytes added, 09:28, 15 December 2011
m
Reverted edits by TermPaperServices (talk) to last revision by Kir
=== Generate a traffic.log ===
Please use crontab to run this script once per hour or day to collect your traffic statistics.
 
(Warning, the counters can overflow if there is too much traffic within that period. Would recommend 15 minute intervals if you expect a lot of traffic)
<pre>
host2:~/bin# cat vz-generate-traffic-log
$MySQL_Passw="INSERT-YOUR-MYSQL-PASSWORD-HERE";
mysql_connect("$MySQL_Host","$MySQL_User","$MySQL_Passw");
$HN=trim(addslashes($_GET["HN"])); // Hardware Node
$handle = fopen ("tmp/{$HN}-traffic","r");
while (!feof($handle)) {
$line = fgets($handle, 4096);
list($date,$time,$ip,$traffic)=explode(" ",$line);
if($traffic>0) {mysql($db,"insert into Traffic (ip,measuringtime,bytes) values('{$ip}','{$date } {$time}','{$traffic}')");}
}
fclose($handle);