aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Lyngstol <kristian@bohemians.org>2015-04-05 10:47:49 +0200
committerKristian Lyngstol <kristian@bohemians.org>2015-04-05 10:47:49 +0200
commit1bf229bef0a79428f06228505e38b9d72de133fa (patch)
treeae3bd045f20a3f8e8fa53ad39cc01d5d84eb5e9d
parent5415913919a40d1e4e3538d86110ab97920b162f (diff)
parentd5f36efa3549a1bd11d03a715511ed2add81124d (diff)
Merge branch 'master' of https://github.com/tech-server/tgmanage
-rwxr-xr-xtools/cubemap-stats.pl63
1 files changed, 63 insertions, 0 deletions
diff --git a/tools/cubemap-stats.pl b/tools/cubemap-stats.pl
new file mode 100755
index 0000000..c6241ab
--- /dev/null
+++ b/tools/cubemap-stats.pl
@@ -0,0 +1,63 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+use POSIX qw(strftime);
+
+my $stats_filename = "/Users/jocke/Desktop/cubemap-tg15-access.log";
+
+my (%streams, %ips);
+my $total = 0;
+my $unique = 1;
+
+open my $stats, "<", $stats_filename
+ or die "$stats_filename: $!";
+while (<$stats>) {
+ chomp;
+ my ($epoch, $ip, $stream, $connected_time, $bytes_sent, $loss_bytes, $loss_events) = /^(\d+) (\S+) (\S+) (\d+) (\d+) (\d+) (\d+)/ or next;
+
+ my $stream_name = stream_name($stream);
+
+ my $date = strftime("%d %b %Y", localtime($epoch));
+
+ if($unique){
+ if($ips{$date}{$ip}){
+ # already viewed this day, skip
+ next;
+ } 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++;
+ }
+ } else {
+ if($streams{$date}{$stream_name}{count}){
+ $streams{$date}{$stream_name}{count}++;
+ } else {
+ $streams{$date}{$stream_name}{count} = 1;
+ }
+ $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";
+ }
+}
+print "\n\nTotal: $total\n";
+
+sub stream_name {
+ my $stream = shift;
+ $stream =~ s/\///g;
+ return $stream;
+}