Skip to content

Commit

Permalink
- lms-traffic: stats summarization for multiple records with the same…
Browse files Browse the repository at this point in the history
… ip address
  • Loading branch information
chilek committed Dec 13, 2006
1 parent b01a17d commit b4e94ca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
54 changes: 32 additions & 22 deletions bin/lms-traffic
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use Getopt::Long;
use vars qw($logfile $configfile $quiet $help $version);
use POSIX qw(strftime);

my $_version = '1.1';
my $_version = '1.9-cvs';

my %options = (
"--traffic-log-file|f=s"=> \$logfile,
Expand Down Expand Up @@ -140,33 +140,43 @@ open(LOGFILE, $logfile);
my(@lines) = <LOGFILE>;
close(LOGFILE);

my %data;

# insert data to lms database
foreach my $line (@lines)
{
my ($ip,$upload,$download) = split('[\t\s]+',$line);
if( $table{$ip} ) # if IP is in our database then we can insert
{
if( $upload || $download ) # don't need zeroes
{
$dbq = $dbase->prepare("INSERT INTO stats (nodeid, dt, download, upload) VALUES ( $table{$ip} , $utsfmt, $download, $upload)");
$dbq->execute();
if(!$quiet)
{
print "IP: $ip\tSend: $upload\t Recv: $download\n";
}
} else
my ($ip,$upload,$download) = split('[\t\s]+',$line);
if( $table{$ip} ) # if IP is in our database then we can insert
{
print "IP: $ip\tSkipped - null data\n";
}
}
else
{
if(!$quiet)
{
print "IP: $ip\tSkipped - not in database\n";
if( $upload || $download ) # don't need zeroes
{
$data{$ip}{'download'} += $download;
$data{$ip}{'upload'} += $upload;

if(!$quiet)
{
print "IP: $ip\tSend: $upload\t Recv: $download\n";
}
} else
{
print "IP: $ip\tSkipped - null data\n";
}
}
else
{
if(!$quiet)
{
print "IP: $ip\tSkipped - not in database\n";
}
}
}
}

while (my ($ip,$record) = each %data)
{
$dbq = $dbase->prepare("INSERT INTO stats (nodeid, dt, download, upload) VALUES ( $table{$ip} , $utsfmt, $record->{'download'}, $record->{'upload'})");
$dbq->execute();
}

# finally
$dbq->finish();
$dbase->disconnect();
3 changes: 2 additions & 1 deletion doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ version ? (????-??-??):
phpui/delete_link_in_customerbalancebox (alec)
- added daemon's tc-ng module supporting tariff+node assignments (alec)
- added possibility to create invoices for past invoiceless liabilities (alec)

- lms-traffic: stats summarization for multiple records with the same ip address (chilek)

version 1.9.3 Zarin (2006-09-19):

- cosmetics on search templates (djrzulf)
Expand Down

0 comments on commit b4e94ca

Please sign in to comment.