Left Menu








Howto set up and use awstats for first time

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.

In this tutorial we will cover installation, configuring and processing only webserver statistics. If you need support for mail or ftp server refer to the Official Website.
AWStats is available througt the official source of the most common distribustions:

Ubuntu/Debian : apt-get install awstats-bin
if you do a search you will see like 5-6 additional packages. Intall the needed ones
Gentoo : emerge awstats
for Gentoo Linux if you want countries listed in your report and have a couple of hosts set USE="vhosts geoip apache2"
Sabayon : equo install awstats
for Sabayon at this time either use emerge (be VERY careful with equo and portage) either install the basic package, no useflags for equo!
ArchLinux : pacman awstats
and so on ... it depends on the distribution


If you have already installed from source skip the next couple steps and continue HERE:

1. Download
$ wget http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz

2. Extract the tarball
$ tar vfx awstats-6.95.tar.gz

Now in order to configure it easy, you will have to configure it from a standart directory : "/usr/local/awstats", so just "mv" the folder
$ sudo mv awstats-6.95 /usr/local/awstats

3. Configure
$ sudo perl /usr/local/awstats/tools/awstats_configure.pl
and follow the instructions .......  You will need the path to your main apache configuration file...
The awstats configure script should greate (path /etc/awstats) a configuration file due to the information that you provided. If not just copy and edit the example configuration file.


4. Copy the awstats.model.conf file to /etc/awstats dir
$ sudo cp /usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf /etc/awstats/awstats.www.linnewbies.com.conf
NOTE : Our site name is www.linnewbies.com, Do not forget to change it according to your needs.

5. Edit the example configuration file to suit your needs
$ sudo nano /etc/awstats/awstats.www.linnewbies.com
You will need all the basic information, like path to vhost access log, site name and so on. You should put a particular attention to these variables :
LogFile  = /var/log/apache2/access_log -- the path to the access_log
LogType = W -- Webserver Log
LogFormat = 4 -- Combined log
SiteDomain = www.linnewbies.com -- the website name

6. Plugins
There are a lot of plugins available, we found useful the GEOip one. The country database is completely free, so don't be afraid to use it! In order to use it you need to have. To use this plugin you are going to need GeoIP Perl module. You can get it from : HERE or simply execute :
$ wget http://geolite.maxmind.com/download/geoip/api/perl/Geo-IP-1.38.tar.gz
now extract the tarball :
$ tar vfx Geo-IP-1.38.tar.gz
Enter (use "cd") the directory
$ cd GeoIP-1.38
Now you can keep on reading or continue with the INSTALLATION manual, anyway in both cases you are going to execute a couple of commands :

6.1.  Geo-IP-1.38/ $ perl Makefile.pl =PP1
The output should be something like :
Checking if your kit is complete...
Looks good
Writing Makefile for Geo::IP
6.2. make
6.3. sudo make test
6.4. sudo make install
After you are done with the install, go to your site configuration and uncomment (remove #) of the geoip line. It is line number about 1312. There you will need to define the full path to your GeoIP.dat file (the free country database). You can download it from HERE

7. Building up a report and adding it to cron
The easiest way to do that is to create a bash script and to add it to cron to be executed every 20 minutes for example. so the script will look like :

#!/bin/bash
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -update

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output -staticlinks > /var/www/localhost/htdocs/stats/stats.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=alldomains -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.alldomains.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=allhosts -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.allhosts.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=lasthosts -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.lasthosts.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=unknownip -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.unknownip.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=alllogins -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.alllogins.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=lastlogins -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.lastlogins.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=allrobots -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.allrobots.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=lastrobots -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.lastrobots.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=urldetail -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.urldetail.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=urlentry -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.urlentry.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=urlexit -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.urlexit.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=browserdetail -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.browserdetail.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=osdetail -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.osdetail.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=unknownbrowser -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.unknownbrowser.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=unknownos -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.unknownos.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=refererse -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.refererse.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=refererpages -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.refererpages.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=keyphrases -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.keyphrases.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=keywords -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.keywords.html

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.linnewbies.com -output=errors404 -staticlinks > /var/www/localhost/htdocs/stats/awstats.www.linnewbies.com.errors404.html

It's needless to say that you will change the site name (www.linnewbies.com) and the path to the output html (/var/www/localhost/htdocs/stats) files according to your needs.
Now save the  file to stats.www.linnewbies.com
In our example we saved this bash script to /home/kickar/stats/stats.www.linnewbies.com and we want this script to be executed on every 20 mins so open up your cron file and add :
*/20 * * * * /bin/bash /home/kickar/stats/stats.www.linnewbies.com
Save it, apply the new cronjob and you  are all set and reay to go. If you have hard time setting up a cron job check out :
Howto Use Cron for first time
You can find the result HERE





Delicious de.li.cio.us


|Home | LinuXchange| Updates | Contact Us | About The Project | Unique Visitors| Sponsorship|