Prev Previous Post   Next Post Next
Old 20th April 2011, 22:03   #1
deviantlinux
Junior Member
 
Join Date: Apr 2011
Posts: 3
Shoutcast with Awstats

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):

Quote:
#!/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";
}
Save it wherever as sc_parse.pl.


Awstats Config File (awstats.conf)

The important Awstats lines are as follows:

Quote:
LogFile="/full/path/to/awstats/tools/logresolvemerge.pl /full/path/to/shoutcast/sc_w3c.lo* |"
Quote:
LogType=S
Quote:
LogFormat=c-ip c-dns date time cs-uri-stem c-status %other sc-bytes x-duration avgbandwidth %method
Quote:
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:

Quote:
# crontab -e
Quote:
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

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
deviantlinux is offline   Reply With Quote
 
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Discussions

Tags
awstats, parse stats, shoutcast, stats, v1.9.8

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump