Prev Previous Post   Next Post Next
Old 20th April 2011, 22:03   #1
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):

#!/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 -c /full/path/to/shoutcast/sc_w3c.log
# Written by Ryan Gehrig
use Getopt::Std;
our $opt_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>;

# 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);
print "ERROR: The specified log file doesnt exist. Exiting.\n";
Save it wherever as

Awstats Config File (awstats.conf)

The important Awstats lines are as follows:

LogFile="/full/path/to/awstats/tools/ /full/path/to/shoutcast/sc_w3c.lo* |"
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/ -c /full/path/to/shoutcast/sc_w3c.log
5 0 * * * /full/path/to/awstats/ -update > /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.

deviantlinux is offline   Reply With Quote
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Discussions

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