Created
May 29, 2013 07:35
-
-
Save jrgm/5668570 to your computer and use it in GitHub Desktop.
because...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
my $requests = {}; | |
sub strip_args { | |
$_ = $_[0]; | |
s/\?ver=.*/\?ver=/; | |
s/\?email=.*/\?email=/; | |
s/\?token=.*/\?token=/; | |
s/\?domain=.*/\?domain=/; | |
s/\?timestamp=.*/\?timestamp=/; | |
return $_; | |
} | |
while (<STDIN>) { | |
next unless m@((?:HEAD|GET|POST|PUT|DELETE|OPTIONS)\s+\S+)\s+[^"]+"\s+(\d{3})@; | |
my ($req, $rc) = ($1, $2); | |
$requests->{$rc} = [] unless $requests->{$rc}; | |
push(@{$requests->{$rc}}, strip_args($req)); | |
} | |
my @rcs = sort { $a <=> $b } keys %$requests; | |
my $totals = {}; | |
for my $rc (@rcs) { | |
my @ary = @{$requests->{$rc}}; | |
print "-> Response code ${rc}:\n"; | |
my $counts = {}; | |
for my $elt (@ary) { | |
$totals->{all}++; | |
$totals->{$rc}++; | |
$counts->{$elt}++; | |
} | |
my @reqkeys = sort { $counts->{$b} <=> $counts->{$a} } keys %$counts; | |
for my $req (@reqkeys) { | |
my $count = $counts->{$req}; | |
printf("%8d %d %s\n", $count, $rc, $req); | |
} | |
} | |
for my $rc (sort keys %$totals) { | |
print "total $rc: ", $totals->{$rc}, "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment