awstats

From Initq

Jump to: navigation, search

Contents

Introduction

Text logs are a wonderful thing for troubleshooting, searching and finding quick fixes for a stuck email, or virtual web server not starting, but text logs are very bad to determine statistical data or finding total traffic. We faced this issue also when we wanted to find out how many emails we received or what was our web traffic like the previous day.

AWStats is a generic log analysis package that offers a nice web interface and can be made to analyze almost any type of logs. It's easy to extend too and quite simple to install.

We are going to show you how to install and configure awstats for web and mail. Once you learn this then later you may also expand it to be used for ftp and other log files.

Install

You should always install the apps that is meant for your distro. We used apt-get and urpmi, you may use yum to install your awstat package.

Once you have installed awstat, check your /etc/awstats directory. The install should have copied a awstats.conf file. You should copy this file to awstats.mail.conf and awstats.web.conf.

awstats.conf files

Change the following in awstats.web.conf

LogFile="/var/log/httpd/access_log"
LogType=W
DirData="/var/lib/awstat"

You may go through the rest of the file and edit as you may seem fit.

Now lets edit the awstats.mail.conf file.

LogFile="perl /usr/bin/maillogconvert.pl standard < /var/log/maillog |"
LogType=M
LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"
SiteDomain="mail.example.com"
LevelForBrowsersDetection=0
LevelForOSDetection=0
LevelForRefererAnalyze=0
LevelForRobotsDetection=0
LevelForWormsDetection=0
LevelForSearchEnginesDetection=0
LevelForFileTypesDetection=0
ShowMenu=1
ShowSummary=HB
ShowMonthStats=HB
ShowDaysOfMonthStats=HB
ShowDaysOfWeekStats=HB
ShowHoursStats=HB
ShowDomainsStats=0
ShowHostsStats=HBL
ShowAuthenticatedUsers=0
ShowRobotsStats=0
ShowEMailSenders=HBML
ShowEMailReceivers=HBML
ShowSessionsStats=0
ShowPagesStats=0
ShowFileTypesStats=0
ShowFileSizesStats=0
ShowBrowsersStats=0
ShowOSStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=0
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=1

Set up cron jobs

We need to set two cron jobs, one for web and one for mail.

00 */2 * * * /var/www/awstats/awstats.pl -update -config=mail
00 */3 * * * /var/www/awstats/awstats.pl -update -config=localhost.localdomain

Update and check

Once you have everything, you can run the following to see if your output files are created.

awstats_updateall.pl now

Apache setup

The default installation should have added the following lines to your /etc/httpd/conf.d/awstats.conf file. to make this set up a bit more secure, we're going to allow access only from web browsers on our LAN and maybe from our other office at 212.87.250.3, all others will get an Access Denied page instead:

Alias /awstats/icon/ /var/www/awstats/icon/
ScriptAlias /awstats/ /var/www/awstats/
<Directory /var/www/awstats/>
    DirectoryIndex awstats.pl
    Options ExecCGI
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1 192.168.0.0/255.255.255.0 212.87.250.3
</Directory>

After you restart your apache and manually run the two cron jobs you can access the web interface. First check for your output files:

[root@lexiana awstats]# cd /var/lib/awstat
[root@lexiana awstat]# pwd
/var/lib/awstat
[root@lexiana awstat]# ls -la
total 112
drwxr-xr-x  2 root root  4096 2008-11-09 21:00 ./
drwxr-xr-x 46 root root  4096 2008-11-08 11:15 ../
-rw-r--r--  1 root root 62922 2008-11-09 18:08 awstats102008.txt
-rw-r--r--  1 root root  6841 2008-11-09 21:00 awstats112008.mail.txt
-rw-r--r--  1 root root 28249 2008-11-09 21:00 awstats112008.txt

Here is how you can access your two links

http://mysite.com/awstats
http://mysite.com/awstats/awstats.pl?config=mail

Vitual servers

You are already done with the install, the only last thing that is left is to make your links pretty so you don't have to type much and identify the config files.

For webstats:

<Virtualhost *:80>
    ServerName webstats.lexiana.com
    DocumentRoot "/var/www/awstats"
    Alias /awstats/icon/ /var/www/awstats/icon/
    ScriptAlias /awstats/ /var/www/awstats/
    <Directory /var/www/awstats>
        DirectoryIndex awstats.pl
        Options ExecCGI
        order deny,allow
        deny from all
        Allow from 127.0.0.1 192.168.0.0/255.255.255.0 71.164.213.0/255.255.255.0
    </Directory>
</Virtualhost>

For mailstats:

NameVirtualHost *:80
<Virtualhost *:80>
    ServerName mailstats.faiveley-fareast.com
    DocumentRoot "/var/www/awstats"
    Alias /awstats/icon/ /var/www/awstats/icon/
    ScriptAlias /awstats/ /var/www/awstats/
    <Directory /var/www/awstats>
        DirectoryIndex awstats.pl
        Options ExecCGI
        order deny,allow
        deny from all
        Allow from 127.0.0.1 192.168.0.0/255.255.255.0 212.87.250.3
    </Directory>

    RewriteEngine   on
    RewriteLog      "/var/log/httpd/rewrite_log"
    RewriteLogLevel 4

    RewriteCond %{REQUEST_URI} ^/mail/?$|^/?$ [NC]
    RewriteCond %{HTTP_HOST} ^(mailstats\..*) [NC]
    RewriteRule (^.*$)   http://%1/awstats/awstats.pl?config=mail

    RewriteCond %{REQUEST_URI} ^/web/?$ [NC]
    RewriteCond %{HTTP_HOST} ^(mailstats\..*) [NC]
    RewriteRule (^.*$)   http://%1/awstats/awstats.pl?config=localhost.localdomain

    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(mail\..*)$ [NC]
    RewriteRule (^.*$)   https://%1 [L,R]

    RewriteCond %{HTTP_HOST} ^webmail\.(.*)$ [NC]
    RewriteRule (^.*$)   https://mail.%1 [L,R]
</Virtualhost>
Personal tools