Editing Traffic accounting with iptables
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 116: | Line 116: | ||
=== Generate a traffic.log === | === Generate a traffic.log === | ||
Please use crontab to run this script once per hour or day to collect your traffic statistics. | 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) | (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> | <pre> | ||
Line 162: | Line 161: | ||
$MySQL_Passw="INSERT-YOUR-MYSQL-PASSWORD-HERE"; | $MySQL_Passw="INSERT-YOUR-MYSQL-PASSWORD-HERE"; | ||
− | mysql_connect($MySQL_Host,$MySQL_User,$MySQL_Passw); | + | mysql_connect("$MySQL_Host","$MySQL_User","$MySQL_Passw"); |
$HN=trim(addslashes($_GET["HN"])); // Hardware Node | $HN=trim(addslashes($_GET["HN"])); // Hardware Node | ||
− | $handle = fopen ("tmp/ | + | $handle = fopen ("tmp/$HN-traffic","r"); |
while (!feof($handle)) { | while (!feof($handle)) { | ||
$line = fgets($handle, 4096); | $line = fgets($handle, 4096); | ||
list($date,$time,$ip,$traffic)=explode(" ",$line); | list($date,$time,$ip,$traffic)=explode(" ",$line); | ||
− | if($traffic>0) {mysql($db,"insert into Traffic (ip,measuringtime,bytes) values(' | + | if($traffic>0) {mysql($db,"insert into Traffic (ip,measuringtime,bytes) values('$ip','$date $time','$traffic')");} |
} | } | ||
fclose($handle); | fclose($handle); |