AWStats is a log analyzer that gives you nice summaries about who's accessing your web server, when they're accessing it, how much bandwidth they're using, etc. Here's a quick run through installing and using AWStats on Gentoo.
Install AWStats:
# emerge -av awstats
Optionally, copy the log files from a remote server:
$ rsync -avz example.net:/var/log/apache2/ example-logs/
Configure AWStats by adjusting the model configuration distributed with AWStats.
$ cp /etc/awstats/awstats.model.conf awstats.example.conf
$ emacs awstats.example.conf
Here's an example config with the options I use:
# AWSTATS CONFIGURE FILE 7.0
Include "awstats.user.conf.common"
LogFile="example-logs/access_log"
LogType=W
LogFormat=1
LogSeparator=" "
SiteDomain="www.example.net"
HostAliases="localhost 127.0.0.1 REGEX[example\.net$]"
DNSLookup=1
DirData="data"
CreateDirDataIfNotExists=1
DirIcons="/usr/share/awstats/wwwroot/icon"
BuildHistoryFormat=text
LoadPlugin="decodeutfkeys"
LoadPlugin="ipv6"
LoadPlugin="hashfiles"
Because awstats.pl
can be invoked interactively through your browser
(depending on how you have it installed), it has a fairly restricted
path. In order to run awstats on files in a random directory
(e.g. for processing your server's logs on another host) you should
use the -configdir
option. Here's an example of parsing the all the
archived logs (my logs are archived as access_log-YYYYMMDD.gz
):
$ for log in example-logs/access_log-*.gz; do awstats.pl -configdir="${PWD}" -config example -LogFile="gzip -cd ${log} |"; done
I also analyze logs from another host, whose logs are archived weekly
as access_log.2.gz
, access_log.3.gz
, etc. To parse the last year
of those archived logs, use something like:
$ for i in $(seq 52 -1 2); do awstats.pl -configdir="${PWD}" -config=example -LogFile="gzip -cd example-logs/access_log.${i}.gz |"; done
After working through the archived logs, you can process the current log file:
$ awstats.pl -configdir="${PWD}" -config=example
Once all the logs have been processed, run
$ awstats.pl -configdir="${PWD}" -config=example -update
To generate the report, run
$ awstats_buildstaticpages.pl -configdir="${PWD}" -config=example -dir=html