Count only audio, show both unique & overall downloads
Also, list the top IP numbers.
This commit is contained in:
parent
7b90af0611
commit
1c5b337d12
1 changed files with 27 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/perl
|
||||
# Copyright (C) 2011, 2014, Bradley M. Kuhn
|
||||
# Copyright (C) 2011, 2019 Bradley M. Kuhn
|
||||
#
|
||||
# This program gives you software freedom; you can copy, modify, convey,
|
||||
# and/or redistribute it under the terms of the GNU General Public License
|
||||
|
@ -20,6 +20,8 @@ use warnings;
|
|||
|
||||
my %data;
|
||||
|
||||
my $overallTotal = 0;
|
||||
|
||||
while (<>) {
|
||||
chomp;
|
||||
next unless /^(\S+)\s+[^"]+"\s*(GET)\s+(\S+)[\s"]/;
|
||||
|
@ -28,23 +30,37 @@ while (<>) {
|
|||
my($ip, $method, $url) = ($1, $2, $3);
|
||||
next unless $method =~ /^\s*GET\s*$/i;
|
||||
|
||||
$url =~ s/\s*\.(ogg|mp3)\s*$/.audio/i; # Treat ogg and mp3 downloads same.
|
||||
next unless $url =~ s/\s*\.(ogg|mp3)\s*$/.audio/i; # Treat ogg and mp3 downloads same, and only count those.
|
||||
$url =~ s/\s*\/$$//; # Always remove trailing slash
|
||||
|
||||
if (not defined $data{$url}{$ip} ) {
|
||||
$data{$url}{$ip} = 0;
|
||||
$data{$url}{__TOTAL_UNIQUE_IP__} = 0 unless
|
||||
defined $data{$url}{__TOTAL_UNIQUE_IP__};
|
||||
$data{$url}{__TOTAL_UNIQUE_IP__}++;
|
||||
}
|
||||
$data{$url}{__TOTAL__} = 0 unless defined $data{$url}{__TOTAL__};
|
||||
$data{$url}{__TOTAL__}++;
|
||||
|
||||
$data{$url}{__UNIQUE_TOTAL__} = 0 unless defined $data{$url}{__UNIQUE_TOTAL__};
|
||||
$data{$url}{__UNIQUE_TOTAL__}++ if not defined $data{$url}{$ip};
|
||||
|
||||
$data{$url}{$ip} = 0 unless defined $data{$url}{$ip};
|
||||
$data{$url}{$ip}++;
|
||||
$data{$url}{__TOTAL__}++;
|
||||
}
|
||||
|
||||
foreach my $url (sort { $data{$b}{__UNIQUE_TOTAL__} <=> $data{$a}{__UNIQUE_TOTAL__}}
|
||||
foreach my $url (sort { $data{$b}{__TOTAL_UNIQUE_IP__} <=> $data{$a}{__TOTAL_UNIQUE_IP__}}
|
||||
keys %data) {
|
||||
print "$url: $data{$url}{__UNIQUE_TOTAL__}\n";
|
||||
print "$url: Unique: $data{$url}{__TOTAL_UNIQUE_IP__} With Dups: $data{$url}{__TOTAL__}\n";
|
||||
print " Top Few IPs: ";
|
||||
my(@ll) = map { $_->[0] }
|
||||
sort { $b->[1] <=> $a->[1] or $b->[0] cmp $a->[0] }
|
||||
map { [ $_, $data{$url}{$_} ] } keys %{$data{$url}};
|
||||
my $cnt = 0;
|
||||
foreach my $ip (@ll) {
|
||||
next if $ip =~ /^__/;
|
||||
last if $cnt++ > 5;
|
||||
print ", " if $cnt > 1;
|
||||
print "$ip"
|
||||
}
|
||||
print "\n";
|
||||
$overallTotal += $data{$url}{__TOTAL_UNIQUE_IP__} if $url =~ /\.audio/;
|
||||
}
|
||||
print "TOTAL AUDIO DOWNLOADS OVERALL: $overallTotal\n";
|
||||
###############################################################################
|
||||
# Local variables:
|
||||
# compile-command: "perl -c oggcast-count.plx"
|
||||
|
|
Loading…
Add table
Reference in a new issue