I wanted to share my experience as I searched Google a lot and couldn't find much help on getting Awstats to parse the w3c shoutcast log (for Shoutcast server v1.9.8).
I ended up writing my own Perl script to add the needed GET text for AwStats to parse the file. I've included it here. Simply run the perl script on your ShoutCast files before you run the awstats script. It will generate a second w3c file with the "_x" extension so awstats can use that and parse it. This is NOT a full howto on how to setup awstats; I assume you've used awstats before.
Perl Script (had to call it php code here on the forum for it to display correctly):
Save it wherever as sc_parse.pl.
Awstats Config File (awstats.conf)
The important Awstats lines are as follows:
Cron Job (to update your stats every night at midnight)
In your cron job that you run every night, first run the perl script, then a few mins later run your normal cron for the awstats. For example:
This would run my perl script first, then update your awstats records. I hope this helps people, and of course feel free to modify the script for whatever you like. Input is appreciated.
Ryan
I ended up writing my own Perl script to add the needed GET text for AwStats to parse the file. I've included it here. Simply run the perl script on your ShoutCast files before you run the awstats script. It will generate a second w3c file with the "_x" extension so awstats can use that and parse it. This is NOT a full howto on how to setup awstats; I assume you've used awstats before.
Perl Script (had to call it php code here on the forum for it to display correctly):
#!/usr/bin/env perl
#
# Parse ShoutCast v1.9.8 W3C log and append "GET" to each log line to pretend it's a web logfile
#
# Usage: perl sc_parse.pl -c /full/path/to/shoutcast/sc_w3c.log
#
# Written by Ryan Gehrig
#
use Getopt::Std;
our $opt_c;
getopts('c:');
# Open the log file
if (-e $opt_c)
{
print "Parsing log '$opt_c' ...\n";
open FILE, "$opt_c" or die "ERROR: Failed to open log file\n";
my @lines = <FILE>;
foreach(@lines)
{
# Ignore comments
if("$_" !~ /^\#/)
{
# Lose newlines
$_ =~ s/\n//;
# Write this line to new log file "sc_w3c.log_x"
open (MYFILE, '>>'.$opt_c.'_x');
print MYFILE "$_" . ' GET' . "\n";
close (MYFILE);
}
}
close(FILE);
}
else
{
print "ERROR: The specified log file doesnt exist. Exiting.\n";
}
#
# Parse ShoutCast v1.9.8 W3C log and append "GET" to each log line to pretend it's a web logfile
#
# Usage: perl sc_parse.pl -c /full/path/to/shoutcast/sc_w3c.log
#
# Written by Ryan Gehrig
#
use Getopt::Std;
our $opt_c;
getopts('c:');
# Open the log file
if (-e $opt_c)
{
print "Parsing log '$opt_c' ...\n";
open FILE, "$opt_c" or die "ERROR: Failed to open log file\n";
my @lines = <FILE>;
foreach(@lines)
{
# Ignore comments
if("$_" !~ /^\#/)
{
# Lose newlines
$_ =~ s/\n//;
# Write this line to new log file "sc_w3c.log_x"
open (MYFILE, '>>'.$opt_c.'_x');
print MYFILE "$_" . ' GET' . "\n";
close (MYFILE);
}
}
close(FILE);
}
else
{
print "ERROR: The specified log file doesnt exist. Exiting.\n";
}
Awstats Config File (awstats.conf)
The important Awstats lines are as follows:
LogFile="/full/path/to/awstats/tools/logresolvemerge.pl /full/path/to/shoutcast/sc_w3c.lo* |"
LogType=S
LogFormat=c-ip c-dns date time cs-uri-stem c-status %other sc-bytes x-duration avgbandwidth %method
LogSeparator=" "
Cron Job (to update your stats every night at midnight)
In your cron job that you run every night, first run the perl script, then a few mins later run your normal cron for the awstats. For example:
# crontab -e
0 0 * * * /full/path/to/sc_parse.pl -c /full/path/to/shoutcast/sc_w3c.log
5 0 * * * /full/path/to/awstats/awstats.pl -update -config=myconfig.com > /dev/null 2>&1
5 0 * * * /full/path/to/awstats/awstats.pl -update -config=myconfig.com > /dev/null 2>&1
This would run my perl script first, then update your awstats records. I hope this helps people, and of course feel free to modify the script for whatever you like. Input is appreciated.
Ryan
Comment