Statistics from your Webserver Logs

Edward Berner of Yosemite Community College District posted this perl script to the WebCT-Admin list this week. It provides count and percentage of webserver error codes from the webserver.logs on Vista 3 and Vista 4, probably CE as well, which I would think has the same webserver log format.

… if you have Server error 500 more than 0.5% over any given time period, that would indicate you’ve got problems.

Running it a couple days in a row has provided me some comfort with some changes we made this week after altering the way NATing works at our firewall. It would more typically be used to monitor the application’s performance.

The script:

——————–
#! /usr/bin/perl -w

use strict;

my ($line, $status, $count, $pct, $record_count); my @fields; my %status_counts;

$record_count = 0;
while ($line = <>) {
if ($line !~ /^#/) {
@fields = split (‘ ‘, $line);
next if $#fields < 5;
$status = $fields[5];
$status_counts{$status} += 1;
$record_count++;
}
}

print "Status Count Percent\n"
print "—— —— ——-\n"
for $status (sort keys %status_counts) {
$count = $status_counts{$status};
$pct = 100.0 * $count / $record_count;

# this next bit is the last line but it’s breaking in this post, so
# I’m inserting a line break that will need to be removed

printf ("%6d %6d %7.2f\n", $status, $count, $pct); }
print "Total records: $record_count\n";

——————–

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s