Created
April 13, 2011 14:32
-
-
Save pstuifzand/917644 to your computer and use it in GitHub Desktop.
Shows the HTTP status of the last few requests in the logfile
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 -w | |
# Name: logtail.pl | |
# Description Shows the HTTP status of the last few requests in the logfile | |
# Usage: tail -f apachelogfile.log | perl logtail.pl | |
# Date: Wed Apr 13 16:31:35 CEST 2011 | |
# Author: Peter Stuifzand | |
# License: GPL3+ | |
use strict; | |
use Parse::AccessLogEntry; | |
use Time::HiRes 'gettimeofday', 'tv_interval'; | |
my $p = Parse::AccessLogEntry->new(); | |
my %stats; | |
my $start=[gettimeofday()]; | |
while (<>) { | |
my $entry = $p->parse($_); | |
my $code = $entry->{code}; | |
$code =~ s/^"//; | |
$code =~ s/"$//; | |
$stats{$code}++; | |
my $diff = tv_interval($start); | |
if ($diff >= 1) { | |
print "--- $diff\n"; | |
for my $code (sort keys %stats) { | |
print $code, "\t", $stats{$code}, "\n"; | |
} | |
%stats=(); | |
$start = [gettimeofday()]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment