]> git.openstreetmap.org Git - dns.git/blob - bin/sumlogs
Update mkgeo to use LWP::UserAgent::Determined + set fair timeout
[dns.git] / bin / sumlogs
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Net::Patricia;
7 use YAML;
8
9 my $pt = new Net::Patricia;
10
11 open(COUNTRIES, "< countries.conf") || die "Can't open /etc/powerdns/countries.conf";
12
13 while (my $line = <COUNTRIES>)
14 {
15     if ($line =~ /^(\d+\.\d+\.\d+\.\d+\/\d+)\s+:127\.\d+\.\d+\.\d+:([a-z]{2})/)
16     {
17         my $address = $1;
18         my $country = uc($2);
19
20         $pt->add_string($address, $country);
21     }
22 }
23
24 close(COUNTRIES);
25
26 my $total_bytes = 0;
27 my %country_bytes;
28
29 while (my $record = <>)
30 {
31     if ($record =~ /^\d+\.\d+\s+\d+\s+(\d+\.\d+\.\d+\.\d+)\s+TCP_[A-Z_]+\/\d+\s+(\d+) (?:GET|HEAD|POST) /)
32     {
33         my $ip = $1;
34         my $bytes = $2;
35         my $country = $pt->match_string($ip);
36
37         $country_bytes{$country} += $bytes if defined($country);
38
39         $total_bytes += $bytes;
40     }
41     elsif ($record =~ /^\d+\.\d+\s+\d+\s+(\d+\.\d+\.\d+\.\d+)\s+UDP_[A-Z_]+\/\d+\s+(\d+) ICP_QUERY /)
42     {
43         # do nothing
44     }
45     else
46     {
47         warn $record;
48     }
49 }
50
51 my %country_bandwidth;
52
53 while (my($country,$bytes) = each %country_bytes)
54 {
55     $country_bandwidth{$country} = $bytes * 300 * 1024 * 1024 / $total_bytes;
56 }
57
58 print Dump(\%country_bandwidth);
59
60 exit 0;