Browse files

uniq by IP

  • Loading branch information...
1 parent 909033d commit 3ad6adb17b7c6efb0f056e8698ba050c1a35cec9 @miyagawa committed Mar 10, 2013
Showing with 18 additions and 4 deletions.
  1. +4 −1 app-gw.psgi
  2. +5 −0 script/daily.sh
  3. +9 −3 script/drawchart.pl
View
5 app-gw.psgi
@@ -15,7 +15,10 @@ my $head = sub {
builder {
enable $head;
- enable 'ReverseProxy';
+ enable sub {
+ my $app = shift;
+ sub { $_[0]->{REMOTE_ADDR} = $_[0]->{HTTP_FASTLY_CLIENT_IP}; $app->($_[0]) };
+ };
mount 'http://sunaba.plackperl.org/' => sub {
return [ 404, ['Content-Type', 'text/plain'], ['Not Found'] ];
};
View
5 script/daily.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+DATE=`date +%Y%m%d`
+mkdir static/versions 2>/dev/null
+tail -10000 access_log | perl script/drawchart.pl > static/versions/index.html
+cp static/versions/index.html static/versions/$DATE.html
View
12 script/drawchart.pl
@@ -1,27 +1,32 @@
#!/usr/bin/env perl
use strict;
+use Time::Piece;
sub versionify {
my $v = shift;
$v =~ /^5\.(\d{3})(\d{3})/
and return join '.', 5, $1+0, $2+0;
}
-my %versions;
+my(%uniq, %versions);
while (<>) {
my @line = split / /, $_;
- my $perl = $line[12];
+ my($ip, $perl) = @line[0, 12];
if ($perl =~ /^perl\/(5\.\d{6})"$/) {
- $versions{$1}++;
+ $uniq{"$ip-$1"}++ or $versions{$1}++;
}
}
my $js_data = join ",\n", map { "[ '@{[versionify($_)]}', $versions{$_} ]" } sort keys %versions;
+my $time = Time::Piece->new;
+my $date = join "-", $time->year, $time->month, $time->day;
+
print <<HTML;
<html>
<head>
+ <title>Perl versions used with cpanm: $date</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
@@ -43,6 +48,7 @@ sub versionify {
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
+ <p class="note">This graph is based on the sample requests sent to the <a href="http://cpanmetadb.plackperl.org/">CPAN Meta DB</a> from cpanm (version 1.604 or later).</p>
</body>
</html>
HTML

0 comments on commit 3ad6adb

Please sign in to comment.