Debianhelp.co.uk

            AWStats Configuration in Debian

What is AWStats?

AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages. It uses a partial information file to be able to process large log files, often and quickly. It can analyze log files from all major server tools like Apache log files (NCSA combined/XLF/ELF log format or common/CLF log format),WebStar, IIS (W3C log format) and a lot of other web, proxy, wap, streaming servers, mail servers and some ftp servers.

Features:

A full log analysis enables AWStats to show you the following information:
* Number of visits, and number of unique visitors,
* Visits duration and last visits,
* Authenticated users, and last authenticated visits,
* Days of week and rush hours (pages, hits, KB for each hour and day of week),
* Domains/countries of hosts visitors (pages, hits, KB, 269 domains/countries detected, GeoIp detection),
* Hosts list, last visits and unresolved IP addresses list,
* Most viewed, entry and exit pages,
* Files type,
* Web compression statistics (for mod_gzip or mod_deflate),
* OS used (pages, hits, KB for each OS, 35 OS detected),
* Browsers used (pages, hits, KB for each browser, each version (Web, Wap, Media browsers: 97 browsers, more than 450 if using browsers_phone.pm library file),
* Visits of robots (319 robots detected),
* Worms attacks (5 worm's families),
* Search engines, keyphrases and keywords used to find your site (The 115 most famous search engines aredetected like yahoo, google, altavista, etc...),
* HTTP errors (Page Not Found with last referrer, ...),
* Other personalized reports based on url, url parameters, referer field for miscellanous/marketing purpose,
* Number of times your site is "added to favourites bookmarks".
* Screen size (need to add some HTML tags in index page).
* Ratio of Browsers with support of: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, PDF reader(need to add some HTML tags in index page).
* Cluster report for load balanced servers ratio.

Requirements:

To use AWStats, you need the following requirements:
* Your server must log web access in a log file you can read.
* You must be able to run perl scripts (.pl files) from command line and/or asCGI (Perl 5.00503 or higher required to run AWStats 6.0 or higher).

If not, you can solve this by downloading last Perl version at ActivePerl (Win32) or Perl.com (Unix/Linux/Other).
See AWStats F.A.Q. to have examples of supported OS and Web servers.

Install AWStats in Debian

# apt-get install awstats

Run the awstats configure script to setup awstats for the domain you want to monitor.
Remember to repeat the configuration process for each domain you want to monitor.

# cd /usr/share/doc/awstats/examples/
#/usr/share/doc/awstats/examples$ perl awstats_configure.pl

Answer the questions asked by the script in which you will need to know the full configuration file path of your web server(e.g. /etc/apache/httpd.conf), and the name of your domain for which you are setting up awstats( full-domain-name in this article).

While running the script it will complain that it is not being run from the default location (/usr/local/awstats).

Answer yes to the prompt to run from the non-standard location as the official Debian package of awstats places
the script in /usr/share/doc/awstats/examples/ which is the Debian way.(See the original for detailed script output)
After the script exits, you should set up an alias for awstats-icons in httpd.conf. Inserted it in the Aliases section.

The awstats_configure.pl script adds it in the end of httpd.conf - comment/remove it.

Your entry for /awstats-icon/ in the Aliases section should look like:

Alias /awstats-icon/ /usr/share/awstats/icon/
<Directory /usr/share/awstats/icon>
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>

Now you can restart apache:

# /etc/init.d/apache restart

Edit the awstats' domain configuration file you just created /etc/awstats/awstats.full-domain-name.conf to have LogFormat=1. Default "LogFormat=4" does not show Browsers, OS, keywords, etc. Do make sure that the parameter SiteDomain has a value of the domain tomonitor. Generate stats the first time by using the following command.

(You can allow awstats to read your apache log file by changing permissions. Run "chmod o+r /var/log/apache/access.log"):

#/usr/lib/cgi-bin/awstats.pl -config=awstats.full-domain-name.conf

Update for config "/etc/awstats/awstats.full-domain-name.conf"
With data in log file "/var/log/apache/access.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 60
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 60 new qualified records.

You can now check the stats in your browser by point it to http://full-domain-name/cgi-bin/awstats.pl?config=full-domain-name.

Set up cron job for awstats as below:

3,33 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.conf -a -r /var/log/apache/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=full-domain-name -update >/dev/null

Setup a prerotate task to run awstats.pl before log rotate and change permissions of log file to 644.

 access.log 644 is basically allowing access to anybody to read the file.

/var/log/apache/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 644 root adm
sharedscripts
prerotate
/usr/lib/cgi-bin/awstats.pl -config=ghaint.no-ip.org -update
endscript
postrotate
if [ -f /var/run/apache.pid ]; then \
if [ -x /usr/sbin/invoke-rc.d ]; then \
invoke-rc.d apache reload > /dev/null; \
else \
/etc/init.d/apache reload > /dev/null; \
fi; \
fi;
endscript
}


This should get awstats running automatically every half an hour with the statistics available via your web browser.
After finishing you might want to go back to the configuration file /etc/awstats/awstats.full-domain-name.conf to
do more tweaking. Reading the documentation in /usr/share/doc/awstats/ is also recommended.