]> git.openstreetmap.org Git - dns.git/blob - bin/sumlogs
Convert gdns map build to be request based
[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+\S+\s+".*"\s+(\d+\.\d+\.\d+\.\d+)\s+".*"\s+(\d+)$/)
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     else
32     {
33         warn $record;
34     }
35 }
36
37 my %country_bandwidth;
38
39 while (my($country,$bytes) = each %country_bytes)
40 {
41     $country_bandwidth{$country} = $bytes * $total_bandwidth / $total_bytes;
42 }
43
44 print Dump(\%country_bandwidth);
45
46 exit 0;