Created
March 28, 2014 02:49
-
-
Save jrgm/9824193 to your computer and use it in GitHub Desktop.
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
use strict; | |
use POSIX qw(strftime); | |
my $slots = {}; | |
# 1395889976.092 10.178.6.136 "GET / HTTP/1.1" 200 71 "-" "ELB-HealthChecker/1.0" "-" 0.002 | |
# 1395962183.009 10.178.6.136 "POST /v1/certificate/sign HTTP/1.1" 200 822 "-" "python-requests/2.2.1 CPython/2.7.3 Linux/3.5.0-23-generic" "54.218.210.15" 0.458 | |
while (<STDIN>) { | |
next unless m@certificate/sign@; | |
#next unless /CPython/; | |
my ($time, $ip, $request, $rc, $bytes, $referer, $ua, $addr, $duration) = | |
/(\S+)\s+(\S+)\s+"([^"]*)"\s+(\d+)\s+(\d+)\s+"([^"]*)"\s+"([^"]*)"\s+"([^"]*)"\s+(\S+)/; | |
next unless $time; # no match | |
$duration = int($duration * 1000); | |
$time = int($time); | |
my $slot = $time - ($time % 60); | |
my $time_s = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime($time)); | |
my $slot_s = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime($slot)); | |
my $dur = $duration; | |
$dur -= $dur % 200; | |
$slots->{$slot_s} ||= { | |
0 => 0, | |
200 => 0, | |
400 => 0, | |
600 => 0, | |
800 => 0, | |
1000 => 0, | |
1200 => 0, | |
1400 => 0, | |
1600 => 0, | |
1800 => 0, | |
2000 => 0, | |
}; | |
$slots->{$slot_s}->{$dur} += 1; | |
# printf("%s %5d %5d\n", | |
# $slot_s, $duration, $dur); | |
} | |
my @blocks = sort keys %$slots; | |
for my $block (@blocks) { | |
my %slot = %{ $slots->{$block} }; | |
my @values = @slot{sort { $a <=> $b } keys %slot}; | |
my $fmt = '%s ' . ('%4d ' x 11 ) . "\n"; | |
printf($fmt, $block, @values); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment