diff options
author | Joachim Tingvold <joachim@tingvold.com> | 2015-04-05 05:32:23 +0200 |
---|---|---|
committer | Joachim Tingvold <joachim@tingvold.com> | 2015-04-05 05:32:23 +0200 |
commit | d5f36efa3549a1bd11d03a715511ed2add81124d (patch) | |
tree | 553ad8d4e6ad40770f1ebc6d07411a9e3925ce01 | |
parent | 835f0309e46765a6e92d8aab178b937c74425359 (diff) |
Crunch cubemap stats.
Combine the access.log-files needed, and crunch it with this to get number of viewers per day for each stream. Also support listing only unique visitors per day (i.e. users with the same IP).
-rwxr-xr-x | tools/cubemap-stats.pl | 63 |
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; +} |