Skip to content

Instantly share code, notes, and snippets.

@pstuifzand
Created April 13, 2011 14:32
Show Gist options
  • Save pstuifzand/917644 to your computer and use it in GitHub Desktop.
Save pstuifzand/917644 to your computer and use it in GitHub Desktop.
Shows the HTTP status of the last few requests in the logfile
#!/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