logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> How-to's & Documentation & Tips View previous topic :: View next topic
Reply to topic   Topic: Apache, Awstats and mod_log_rotate
Author
Mitron



Joined: 04 Jan 2006
Posts: 63

PostPosted: Sun 30 Mar '08 19:29    Post subject: Apache, Awstats and mod_log_rotate Reply with quote

Here's how I setup Apache and Awstats with log rotation.

I have Apache 2.2.8 setup with numerous vitural hosts, each with their own logs folder and mod_log_rotate setup to rotate logs on a daily basis. Awstats is also run on a daily basis for all virtural hosts.

1.) Install Apache with mod_log_rotate from Apache Lounge. In httpd.conf add the following:
Code:
LoadModule log_rotate_module modules/mod_log_rotate.so


2.) Open your httpd-vhosts.conf and edit each vhosts' log entry like this:
Code:
   
<IfModule log_config_module>
    <IfModule log_rotate_module>
        RotateLogs On
        RotateLogsLocalTime On
        RotateInterval 86400 60
        CustomLog "x:/www/site1.com/logs/access.%Y%m%d.log" combined
    </IfModule>
</IfModule>


3.) Install Awstats and build a config file for each virtual hosts per their documentation. I simply used a text editor to edit the awstats.model.conf and save a changed copy for each virtual host. Since your rotating the log files Awstats will need to combine all the logs in order to accurately create the stats. To do this, make sure you edit the LogFile line like this:
Code:
LogFile="x:/path/to/awstats/tools/logresolvemerge.pl
x:/www/site1.com/logs/access*.log |"


4.) The last step is to use Task Scheduler to run a batch file to execute the CLI for Awstats on all virtual hosts. I use an edited version of robolog to accomplish this:
Code:
SET a=x:\path\to\awstats\wwwroot\cgi-bin\
cls
ECHO.AWSTATS BATCH LOG
ECHO.===================================
for /f "tokens=*" %%b in ('dir /ad /on /b "x:\www"') do (
cls
ECHO.
ECHO.AWSTATS BATCH LOG
ECHO.===================================
ECHO.Checking conf for directory: %%b
ECHO.
IF EXIST %a%awstats.%%b.conf perl %a%awstats.pl -config=%%b -update"
ECHO.
ECHO.
)

The above batch file assumes that you have all your virtual hosts located in x:\www\site1.com, x:\www\site2.com, etc. and your awstats.*.conf files are named from the folder name, i.e. awstats.site1.com.conf, awstats.site2.com.conf. I named the above batch file awstats.bat and placed it in the x:\path\to\awstats\wwwroot\cgi-bin folder.

5.) Now add the batch file to Task Scheduler and set it to run once per day. You can also run the batch file from a CMD prompt to test it.
This procedure will create a new access.log file per day for each vhost with a readable date and allow Awstats to read all log files in order to create the stats for each site.
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3094
Location: Hilversum, NL, EU

PostPosted: Sun 30 Mar '08 19:53    Post subject: Reply with quote

Great write up, thanks! It stimulates me to write up my setup:

I use one log file for all Vitual hosts, by adding %v in front:

LogFormat "%v %h %l %u %t .....

In the access.log I get then:

www.apachelounge.com 78.99.131.97 - - [30/Mar/2008:13:04:26 +0200] .....

I too made for all Vhosts a awstats conf file, for example for the Apache Lounge:

LogFile="f:/log/apache/access.log"
LogType=W
LogFormat = "%virtualname %host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
LogSeparator=" "
SiteDomain="www.apachelounge.com"
HostAliases="www.apachelounge.com apachelounge.com"

I run awstats with Cron (Sambar) every day once with:

c:/perl/bin/perl.exe f:/web/stat/aw/awstats_updateall.pl now -awstatsprog=f:/web/stat/aw/awstats.pl -configdir=f:/web/stat/aw

Btw.
I do not use rotate logs, I have a Dummy awstats conf file as last (named it awstats.www.xxxx.zzzz.com.conf) which clears the log, with the lines in it:

SiteDomain="zzzz"
HostAliases="zzzz"
PurgeLogFile=1

For every Vhost I have also rewrite code, so apachelounge.com (without www) is appearing as www.apachelounge.com in the log file.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.apachelounge\.com [NC]
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^/(.*) http://www\.apachelounge\.com/$1 [L,R=301]


Thanks again,

Steffen
Back to top
djc



Joined: 04 Dec 2007
Posts: 37

PostPosted: Mon 14 Apr '08 10:42    Post subject: Reply with quote

Mitron,

Thanks for the great batch file and walkthrough. It works great!
Back to top
djc



Joined: 04 Dec 2007
Posts: 37

PostPosted: Fri 20 Jun '08 2:59    Post subject: Re: Apache, Awstats and mod_log_rotate Reply with quote

I noticed it has been taking longer and longer to run the batch file at night. Should I be archiving older log files? If so, at what threshold? Prior month's?
Back to top
Mitron



Joined: 04 Jan 2006
Posts: 63

PostPosted: Sat 21 Jun '08 9:36    Post subject: Reply with quote

I would think that would depend on how far back you want to provide the stats to your users.
Back to top


Reply to topic   Topic: Apache, Awstats and mod_log_rotate View previous topic :: View next topic
Post new topic   Forum Index -> How-to's & Documentation & Tips