Plexus log file summaries

Tony Sanders (sanders@bsdi.com)
Fri, 18 Jun 1993 17:31:05 -0500


Here is some log file summerizing scripts for Plexus log files (it should
be easy to modify this for other formats). I will be including them in
the next release.

I have two scripts, usage.byhost and usage.byurl which generates output
like the following. They read in the previous results and then merge the
current log info. There is also a script that runs them and then empties
and restarts the log file.

>>>>>> usage.host
694 137.39.95.2 (this is my host)
434 xxx.xxx.xxx.xx
...

>>>>>> usage.url
1621 /
1366 /demo/icons.html
1337 /decode_walk
...

Note that this usage.byurl "folds" some directories into a single line.
You can add folding at any time and the summary will reflect the change,
however you cannot unfold once you have folded. It's pretty easy to figure
out how to add or remove items from the list (it's the first function in
the script.

#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: summary usage.byhost usage.byurl
# Wrapped by sanders@austin.BSDI.COM on Fri Jun 18 17:24:28 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'summary' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'summary'\"
else
echo shar: Extracting \"'summary'\" \(413 characters\)
sed "s/^X//" >'summary' <<'END_OF_FILE'
X#!/bin/sh
X
X#
X# summerize host usage
X#
Xbin/usage.byhost
X
X#
X# summerize the URL usage and empty the log.
X#
Xbin/usage.byurl
X
X#
X# append the log to log.summary
X#
Xecho ------- SUMMARY ------- >> log.summary
Xcat log >> log.summary
X
X#
X# restart the log file
X#
Xrm -f log; touch log; .s chown sanders.www log
Xpid=`ps auxww | perl -ne '/^www.*plexus/ && do { ($a,$b) = split(" ",$_); print $b; exit; }'`
X.s kill -USR1 $pid
END_OF_FILE
if test 413 -ne `wc -c <'summary'`; then
echo shar: \"'summary'\" unpacked with wrong size!
fi
chmod +x 'summary'
# end of 'summary'
fi
if test -f 'usage.byhost' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'usage.byhost'\"
else
echo shar: Extracting \"'usage.byhost'\" \(657 characters\)
sed "s/^X//" >'usage.byhost' <<'END_OF_FILE'
X#!/usr/bin/perl
X#
X# usage.byhost
X#
X$log = $ARGV[0] || "/usr/local/www/log";
X$sum = "usage.host";
Xif ( -f $sum ) {
X rename ($sum, "$sum-") || die "rename $sum $sum-: $!";
X}
Xif ( -f "$sum-" ) {
X open(SUM, "< $sum-") || die "$sum-: $!";
X while(<SUM>) {
X ($a, $b) = split(" ", $_, 2);
X $count{$b} += $a;
X }
X close(SUM);
X}
Xopen(SUM, "> /tmp/$sum") || die "$sum: $!";
X
Xopen(LOG, $log) || die "$log: $!";
Xwhile(<LOG>) {
X next if /^-/;
X chop;
X s/ .*//;
X $count{$_}++;
X}
Xclose(LOG);
X
Xforeach $i (keys(%count)) {
X printf(SUM "%6d %s\n", $count{$i}, $i);
X}
Xclose(SUM);
Xsystem("sort -rn /tmp/$sum > $sum ; rm -f /tmp/$sum");
END_OF_FILE
if test 657 -ne `wc -c <'usage.byhost'`; then
echo shar: \"'usage.byhost'\" unpacked with wrong size!
fi
chmod +x 'usage.byhost'
# end of 'usage.byhost'
fi
if test -f 'usage.byurl' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'usage.byurl'\"
else
echo shar: Extracting \"'usage.byurl'\" \(1104 characters\)
sed "s/^X//" >'usage.byurl' <<'END_OF_FILE'
X#!/usr/bin/perl
X#
X# usage.byurl
X#
Xsub junk {
X $_[0] =~ s,^(/decode_walk)[/\?].*,\1, && return 1;
X $_[0] =~ s,^(/bookmark)[/\?].*,\1, && return 1;
X $_[0] =~ s,^(/finger)[/\?].*,\1, && return 1;
X $_[0] =~ s,^(/date)[/\?].*,\1, && return 1;
X $_[0] =~ s,^(/calendar)[/\?].*,\1, && return 1;
X $_[0] =~ s,^(/bsdi-man)[/\?].*,\1, && return 1;
X $_[0] =~ s,^(/faces)[/\?].*,\1, && return 1;
X 0;
X}
X$log = $ARGV[0] || "/usr/local/www/log";
X$sum = "usage.url";
Xif ( -f $sum ) {
X rename ($sum, "$sum-") || die "rename $sum $sum-: $!";
X}
Xif ( -f "$sum-" ) {
X open(SUM, "< $sum-") || die "$sum-: $!";
X while(<SUM>) {
X ($a, $b) = split(" ", $_, 2);
X &junk($b);
X $count{$b} += $a;
X }
X close(SUM);
X}
Xopen(SUM, "> /tmp/$sum") || die "$sum: $!";
X
Xopen(LOG, $log) || die "$log: $!";
Xwhile(<LOG>) {
X next if /^-/ || /^137.39.95.2 / || /^127.0.0.1 /;
X next unless ($b) = m/GET ([^ \t\r\n]*)/;
X &junk($b);
X $count{$b}++;
X}
Xclose(LOG);
X
Xforeach $i (keys(%count)) {
X printf(SUM "%6d %s\n", $count{$i}, $i);
X}
Xclose(SUM);
Xsystem("sort -rn /tmp/$sum > $sum ; rm -f /tmp/$sum");
END_OF_FILE
if test 1104 -ne `wc -c <'usage.byurl'`; then
echo shar: \"'usage.byurl'\" unpacked with wrong size!
fi
chmod +x 'usage.byurl'
# end of 'usage.byurl'
fi
echo shar: End of shell archive.
exit 0