Skip to content

Instantly share code, notes, and snippets.

@jrgm
Created May 29, 2013 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrgm/5668570 to your computer and use it in GitHub Desktop.
Save jrgm/5668570 to your computer and use it in GitHub Desktop.
because...
#!/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