aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoachim Tingvold <joachim@tingvold.com>2015-04-16 21:10:29 +0200
committerJoachim Tingvold <joachim@tingvold.com>2015-04-16 21:10:29 +0200
commitcf10d6ed33446032a86c9d58b964c5fbda121550 (patch)
tree96c6e4a3b285887dfb63a3915b81dd14069ddd0f
parentd5f36efa3549a1bd11d03a715511ed2add81124d (diff)
Improved streamstats.
-rwxr-xr-xbootstrap/make-dhcpd6.pl10
-rwxr-xr-x[-rw-r--r--]sql/strip.pl0
-rwxr-xr-xtools/cubemap-stats.pl151
3 files changed, 113 insertions, 48 deletions
diff --git a/bootstrap/make-dhcpd6.pl b/bootstrap/make-dhcpd6.pl
index 51d93c4..f678c14 100755
--- a/bootstrap/make-dhcpd6.pl
+++ b/bootstrap/make-dhcpd6.pl
@@ -34,23 +34,21 @@ if ( not -f $dhcpd_conf )
# IPv6 address valid lifetime
# (at the end the address is no longer usable by the client)
-# (set to 30 days, the usual IPv6 default)
+# (usual IPv6 default is 30 days)
default-lease-time 3600;
# IPv6 address preferred lifetime
# (at the end the address is deprecated, i.e., the client should use
# other addresses for new connections)
-# (set to 7 days, the usual IPv6 default)
+# (usual IPv6 default is 7 days)
preferred-lifetime 3600;
# T1, the delay before Renew
# (default is 1/2 preferred lifetime)
-# (set to 1 hour)
option dhcp-renewal-time 1800;
# T2, the delay before Rebind (if Renews failed)
# (default is 3/4 preferred lifetime)
-# (set to 2 hours)
option dhcp-rebinding-time 1800;
# Enable RFC 5007 support
@@ -58,10 +56,10 @@ allow leasequery;
# Set preference to 255 (maximum) in order to avoid waiting for
# additional servers when there is only one
-#option dhcp6.preference 255;
+option dhcp6.preference 255;
# Server side command to enable rapid-commit (2 packet exchange)
-#option dhcp6.rapid-commit;
+option dhcp6.rapid-commit;
# The delay before information-request refresh
# (minimum is 10 minutes, maximum one day, default is to not refresh)
diff --git a/sql/strip.pl b/sql/strip.pl
index 1402130..1402130 100644..100755
--- a/sql/strip.pl
+++ b/sql/strip.pl
diff --git a/tools/cubemap-stats.pl b/tools/cubemap-stats.pl
index c6241ab..401424a 100755
--- a/tools/cubemap-stats.pl
+++ b/tools/cubemap-stats.pl
@@ -1,63 +1,130 @@
-#! /usr/bin/perl
+#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
+use NetAddr::IP;
+use Net::IP;
-my $stats_filename = "/Users/jocke/Desktop/cubemap-tg15-access.log";
+my (%streams, %ips, %total);
+$total{count}{c} = 0;
+$total{unique_count}{c} = 0;
+$total{count}{int} = 0;
+$total{unique_count}{int} = 0;
+$total{count}{ext} = 0;
+$total{unique_count}{ext} = 0;
-my (%streams, %ips);
-my $total = 0;
-my $unique = 1;
+sub stream_name {
+ my $stream = shift;
+ $stream =~ s/\///g;
+ return $stream;
+}
+
+# Is client in the network?
+sub is_in_network{
+ my ($ip, $ipv4, $ipv6) = @_;
+ my $in_scope = 0;
+ my $ipv4_range = NetAddr::IP->new($ipv4);
+ my $ipv6_range = NetAddr::IP->new($ipv6);
+
+ if (Net::IP->new($ip)->ip_is_ipv4()){
+ if (NetAddr::IP->new($ip)->within($ipv4_range)){
+ $in_scope = 1;
+ }
+ } else {
+ if (NetAddr::IP->new($ip)->within($ipv6_range)){
+ $in_scope = 1;
+ }
+ }
+
+ return $in_scope;
+}
+
+# add count
+sub add_count{
+ my ($date, $stream_name, $count_name, $count_type) = @_;
+
+ if($streams{$date}{$stream_name}{$count_name}{$count_type}){
+ $streams{$date}{$stream_name}{$count_name}{$count_type}++;
+ } else {
+ $streams{$date}{$stream_name}{$count_name}{$count_type} = 1;
+ }
+}
-open my $stats, "<", $stats_filename
- or die "$stats_filename: $!";
-while (<$stats>) {
+sub print_info{
+ foreach my $date (sort keys %streams) {
+ print "### $date\n";
+ foreach my $stream (sort keys %{$streams{$date}}){
+ my $stream_name = stream_name($stream);
+ printf "\t%s: %s (%s) - Int: %s (%s), Ext: %s (%s)\n",
+ $stream_name,
+ $streams{$date}{$stream}{count}{c},
+ $streams{$date}{$stream}{unique_count}{c},
+ $streams{$date}{$stream}{count}{int},
+ $streams{$date}{$stream}{unique_count}{int},
+ $streams{$date}{$stream}{count}{ext},
+ $streams{$date}{$stream}{unique_count}{ext},
+ }
+ }
+ print "\n\nTotal: $total{count}{c} ($total{unique_count}{c})\n";
+ print "Internal: $total{count}{int} ($total{unique_count}{int})\n";
+ print "External: $total{count}{ext} ($total{unique_count}{ext})\n";
+}
+
+while (<STDIN>) {
chomp;
my ($epoch, $ip, $stream, $connected_time, $bytes_sent, $loss_bytes, $loss_events) = /^(\d+) (\S+) (\S+) (\d+) (\d+) (\d+) (\d+)/ or next;
+
+ next if ($stream =~ m/-/);
+ next if ($stream =~ m/test/);
my $stream_name = stream_name($stream);
my $date = strftime("%d %b %Y", localtime($epoch));
+
+ my $internal = is_in_network($ip, '151.216.128.0/17', '2a02:ed02::/32');
+ unless($internal){
+ # check server /24
+ $internal = is_in_network($ip, '185.12.59.0/24', '2a02:ed02::/32');
+ }
- if($unique){
- if($ips{$date}{$ip}){
- # already viewed this day, skip
- next;
+ print "$date, $stream_name, $ip, $internal\n";
+
+ if($ips{$date}{$ip}){
+ # already viewed this day
+
+ add_count($date, $stream_name, 'count', 'c');
+
+ if($internal){
+ add_count($date, $stream_name, 'count', 'int');
+ $total{count}{int}++;
} else {
- # not viewed this day, add
- $ips{$date}{$ip} = 1;
-
- if($streams{$date}{$stream_name}{count}){
- $streams{$date}{$stream_name}{count}++;
- } else {
- $streams{$date}{$stream_name}{count} = 1;
- }
- $total++;
+ add_count($date, $stream_name, 'count', 'ext');
+ $total{count}{ext}++;
}
+
+ $total{count}{c}++;
} else {
- if($streams{$date}{$stream_name}{count}){
- $streams{$date}{$stream_name}{count}++;
+ # not viewed this day
+ $ips{$date}{$ip} = 1;
+
+ add_count($date, $stream_name, 'count', 'c');
+ add_count($date, $stream_name, 'unique_count', 'c');
+
+ if($internal){
+ add_count($date, $stream_name, 'count', 'int');
+ add_count($date, $stream_name, 'unique_count', 'int');
+ $total{count}{int}++;
+ $total{unique_count}{int}++;
} else {
- $streams{$date}{$stream_name}{count} = 1;
+ add_count($date, $stream_name, 'count', 'ext');
+ add_count($date, $stream_name, 'unique_count', 'ext');
+ $total{count}{ext}++;
+ $total{unique_count}{ext}++;
}
- $total++;
- }
-}
-close $stats;
-
-foreach my $date (sort keys %streams) {
- print "### $date\n";
- foreach my $stream (sort keys %{$streams{$date}}){
- next if ($stream =~ m/-/);
- next if ($stream =~ m/test/);
- my $stream_name = stream_name($stream);
- print "\t$stream_name: $streams{$date}{$stream}{count}\n";
+
+ $total{count}{c}++;
+ $total{unique_count}{c}++;
}
}
-print "\n\nTotal: $total\n";
-sub stream_name {
- my $stream = shift;
- $stream =~ s/\///g;
- return $stream;
-}
+print_info(); \ No newline at end of file