User Tools

Site Tools


technology:linux:visitors

Visitors script

I was searching the Ubuntu repository one afternoon for a way to analyze my web server logs. I ran across a tool called visitors. Sounded simple, so I gave it a try. 5 minutes later, it had analyzed my logs and created a graph for me–an impressive start. But I wanted to change the options and run it automatically each day, so I created a script and dropped it into /etc/cron.daily. Unfortunately, that didn't give me much history because my apache logs are rotated weekly. So I devised a script to concat my log history files and have the visitors tool read that instead of the active file. The result is a graph and a report that spans a much longer time period.

This is an example of what the graph loos like on another site I run:

And here's the script that makes it happen:

#! /bin/sh
 
tempdir=/tmp/visitors
apachedir=/var/log/apache2
 
mkdir $tempdir
cp $apachedir/access* $tempdir
cd $tempdir
gzip -d *.gz
cat * > all.log
 
visitors -A -m 30 $tempdir/all.log --trails --prefix http://your.domain.com > /var/www/stats/report.html
visitors -V $tempdir/all.log --prefix http://your.domain.com > /var/www/stats/graph.dot
visitors -V $tempdir/all.log --prefix http://your.otherdomain.com --prefix YourInternalHostName > /var/www/stats/graph2.dot
dot /var/www/stats/graph.dot -Tpng > /var/www/stats/graph.png
dot /var/www/stats/graph2.dot -Tpng > /var/www/stats/graph2.png
cd ..
rm -rf $tempdir
/home/cfreyer/public_html/data/pages/technology/linux/visitors.txt · Last modified: 2007/07/19 16:02 by Chris Freyer