Skip to content

Instantly share code, notes, and snippets.

@ixti
Last active August 29, 2015 14:10
Show Gist options
  • Save ixti/9a5fb9e814a29229f8d2 to your computer and use it in GitHub Desktop.
Save ixti/9a5fb9e814a29229f8d2 to your computer and use it in GitHub Desktop.
Simple apache logs parser and counter of calls
#!/usr/bin/perl
while (<>) {
if (/^[^"]+"([A-Z]+)\s([^"? ]+)[^"]*"\s(\d+)/) {
my $m = $1;
my $p = $2;
my $s = $3;
$p =~ s/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/{uuid}/;
$records{ "$m $p [$s]" } += 1;
}
}
while (my ($key, $value) = each(%records)) {
print "$key x$value\n";
}
@ixti
Copy link
Author

ixti commented Dec 3, 2014

Usage:

cat /var/log/apache.log | perl logs_parser.pl

@ixti
Copy link
Author

ixti commented Dec 3, 2014

Output:

GET /foo [200] x123
POST /bar [200] x91
GET /baz [200] x100
GET /baz [500] x31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment