]> git.openstreetmap.org Git - dns.git/blob - bin/sumlogs
Correct konqi's IPv6 address
[dns.git] / bin / sumlogs
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Geo::IP;
7 use YAML;
8
9 my $gi = Geo::IP->open("/usr/share/GeoIP/GeoIP.dat", GEOIP_MEMORY_CACHE);
10 my $total_bandwidth = 560 * 1024 * 1024;
11 my $total_bytes = 0;
12 my %country_bytes;
13
14 while (my $record = <>)
15 {
16     if ($record =~ /^\d+\.\d+\s+\d+\s+(\d+\.\d+\.\d+\.\d+)\s+TCP_[A-Z_]+\/\d+\s+(\d+) (?:GET|HEAD|POST|OPTIONS|PROPFIND) /)
17     {
18         my $ip = $1;
19         my $bytes = $2;
20         my $country = $gi->country_code_by_addr($ip);
21
22         if (defined($country) &&
23             $country ne "A1" && $country ne "A2" && 
24             $country ne "01" && $country ne "--")
25         {
26             $country_bytes{$country} += $bytes;
27         }
28
29         $total_bytes += $bytes;
30     }
31     elsif ($record =~ /^\d+\.\d+\s+\d+\s+(\d+\.\d+\.\d+\.\d+)\s+TCP_DENIED\/\d+\s+(\d+) /)
32     {
33         # do nothing
34     }
35     elsif ($record =~ /^\d+\.\d+\s+\d+\s+(\d+\.\d+\.\d+\.\d+)\s+UDP_[A-Z_]+\/\d+\s+(\d+) ICP_QUERY /)
36     {
37         # do nothing
38     }
39     else
40     {
41         warn $record;
42     }
43 }
44
45 my %country_bandwidth;
46
47 while (my($country,$bytes) = each %country_bytes)
48 {
49     $country_bandwidth{$country} = $bytes * $total_bandwidth / $total_bytes;
50 }
51
52 print Dump(\%country_bandwidth);
53
54 exit 0;