HOW-TO
Use Analog for Virtual Hosts
(Using Separate Logfiles)

This HOW-TO written by Peter Rose.
Converted to HTML and Step Three added by Stephen Turner.

One of the great things about Analog is that it can easily be used to offer different customised output to multiple virtual hosts on the same server.

This is an obvious asset if you host several domains on your server and want to offer all your customers the benefit of daily/weekly/monthly Analog stats, but not all of them require the same level of reporting or the same 'look'.

This real-world example is based on Apache 1.3.12 running on RedHat Linux 6.1, but should be applicable to any Unix-like platform. Steps Two and Three, and the general ideas, should be helpful on Windows NT and other operating systems, but for the details you'll have to ask someone else :-)

Step One

Make the necessary entries in the Apache Virtual Host sections.

Here's an example from my httpd.conf:

<VirtualHost 212.87.82.24>
ServerName www.ontiles.com
SSLDisable
DocumentRoot /home/httpd/html/tileshop
ServerAdmin webmaster@ontiles.com
CustomLog logs/ontiles-referer_log  referer
TransferLog logs/ontiles.com-access_log
</VirtualHost>

<VirtualHost 212.87.82.24>
ServerName www.nuw-maas.co.uk
SSLDisable
DocumentRoot /home/httpd/html/nuwmaas
ServerAdmin webmaster@cyberscreen.com
TransferLog logs/nuw-maas-access_log
</VirtualHost>

Here you can see there are 2 virtual hosts with different logging requirements:

ontiles.com wants to get a referer report as well as the regular access statistics, whereas nuw-maas.co.uk only needs the basic access stats.

Step Two

Create a separate analog.cfg file for each domain. For ontiles.com, we have a file called (with stunning originality) ontilesanalog.cfg. The relevant parts from this are as follows:
LOGFILE /etc/httpd/logs/ontiles.com-access_log
LOGFORMAT REFERRER
LOGFILE /etc/httpd/logs/ontiles-referer_log
OUTFILE /home/httpd/html/cyberscreen/stats/ontiles_stats.html 
HOSTNAME "ONTILES.COM"
HOSTURL "http://www.ontiles.com/"
IMAGEDIR "http://www.cyberscreen.com/images/"
LOGO "ontileslogo.jpg"
STYLESHEET ontilesanalogstyle.css
Note the order in which the LOGFILE and LOGFORMAT commands appear - if the LOGFORMAT REFERRER is not before the LOGFILE /etc/httpd/logs/ontiles-referer_log, it won't work! You can see also that we're giving the reports for this domain their own logo at the top of the page and are using a stylesheet that will match that of their website. Not essential, but you can't beat the finishing touches :-)

Now here's the same section for the analog.cfg file for the other virtual host - which, yes, you've guessed it, is called nuw-maasanalog.cfg.

LOGFILE /etc/httpd/logs/nuw-maas-access_log
OUTFILE /home/httpd/html/cyberscreen/stats/nuw-maas_stats.html 
HOSTNAME "WWW.NUW-MAAS.CO.UK"
HOSTURL "http://www.nuw-maas.co.uk/"
IMAGEDIR "http://www.cyberscreen.com/images/"
LOGO "nuw-maaslogo.jpg"
STYLESHEET nuw-maassanalogstyle.css
So by this time, you get the idea. This domain don't need the referrer report, but they would like their own groovy logo and stylesheet applied to the output. You can, of course, take the opportunity within each domain's analog.cfg file to tweak the output appearance, request floors and so on according to each host's requirements.

Step Three

We also want a report for our own use with a summary of the usage for all the virtual hosts. So we need to analyse all the logfiles together. The problem is that the filenames appear in the logfiles as just /index.html for example, but we want to see http://www.ontiles.com/index.html, so that we know which files belong to which virtual hosts. This is where the second argument to the LOGFILE command comes in. This argument specifies a prefix to add to the filenames in that logfile. You can see this in this configuration file, which we'll call all.cfg:
LOGFILE /etc/httpd/logs/ontiles.com-access_log http://www.ontiles.com
LOGFILE /etc/httpd/logs/nuw-maas-access_log    http://www.nuw-maas.co.uk
OUTFILE /home/httpd/html/cyberscreen/stats/overall_stats.html 
HOSTNAME "Cyberscreen"
IMAGEDIR "http://www.cyberscreen.com/images/"
SUBDIR http://*
Notice the SUBDIR command at the end. This enables us to see the amount of traffic for each virtual host in the Directory Report. This information is not in the Virtual Host Report, because the virtual host name is just part of the filename, not an item on its own.

When we run this report, analog will give us a "possible double counting" warning. This just means that the dates for the logfiles overlap, and it's nothing to worry about because all the logfiles are from separate virtual hosts.

Step Four

Now we have to knock up a little shell script to tell Analog to make a report on the stats for our different hosts at runtime. This works for me:
#!/bin/sh

cd /etc/httpd/analog4.0
./analog -G +gontilesanalog.cfg
./analog -G +gnuwmaasanalog.cfg
./analog -G +gall.cfg
Obviously, the first line reflects the location of my analog - yours may well be somewhere else. And of course, if you've put Analog in your $PATH, you won't need the ./ at the beginning of each line. What we're doing here is simply running Analog twice using a different config file each time. I won't say you can do this ad infinitum, but I'm up to 20 virtual hosts and Analog processes the whole lot in seconds. The important switches are the -G , which tells Analog not to use the default config file, and the +g in front of each cfg filename, which tells Analog to use that particular config file. No, you don't leave a space before the filename.

Step Five

Save the above script as 'runanalog' (or whatever) and chmod it 755. Now you can use the cron daemon to execute analog on all your virtual hosts automatically at whatever frequency you desire. In the case of Linux, this is a definite no-brainer as under /etc you will find the directories cron.daily, cron.weekly or cron.monthly. My users like to have their stats pages updated on a daily basis, so I just copied 'runanalog' into cron.daily, but you could equally run weekly or monthly. If you offer a different service to different hosts, you could have one 'runanalog' or the daily stats junkies and another version in cron.monthly with the hosts that can't handle too much information.

And that's it! You now have Analog reports automatically generated and customised for all your virtual hosts.


Back to index of How-To's