Add AWStats post.
[blog.git] / posts / AWStats.mdwn
1 [AWStats][] is a log analyzer that gives you nice summaries about
2 who's accessing your web server, when they're accessing it, how much
3 bandwidth they're using, etc.  Here's a quick run through installing
4 and using AWStats on [[Gentoo]].
5
6 Install AWStats:
7
8     # emerge -av awstats
9
10 Optionally, copy the log files from a remote server:
11
12     $ rsync -avz example.net:/var/log/apache2/ example-logs/
13
14 Configure AWStats by adjusting the model configuration distributed
15 with AWStats.
16
17     $ cp /etc/awstats/awstats.model.conf awstats.example.conf
18     $ emacs awstats.example.conf
19
20 Here's an example config with the options I use:
21
22     # AWSTATS CONFIGURE FILE 7.0
23     Include "awstats.user.conf.common"
24     LogFile="example-logs/access_log"
25     LogType=W
26     LogFormat=1
27     LogSeparator=" "
28     SiteDomain="www.example.net"
29     HostAliases="localhost 127.0.0.1 REGEX[example\.net$]"
30     DNSLookup=1
31     DirData="data"
32     CreateDirDataIfNotExists=1
33     DirIcons="/usr/share/awstats/wwwroot/icon"
34     BuildHistoryFormat=text
35     LoadPlugin="decodeutfkeys"
36     LoadPlugin="ipv6"
37     LoadPlugin="hashfiles"
38
39 Because `awstats.pl` can be invoked interactively through your browser
40 (depending on how you have it installed), it has a fairly restricted
41 path.  In order to run awstats on files in a random directory
42 (e.g. for processing your server's logs on another host) you should
43 use the full path to your config file.  Here's an example of parsing
44 the all the archived logs (my logs are archived as
45 `access_log-YYYYMMDD.gz`):
46
47     $ for log in example-logs/access_log-*.gz; do awstats.pl -config="${PWD}/awstats.example.conf" -LogFile="gzip -cd ${log} |"; done
48
49 I also analyze logs from another host, whose logs are archived weekly
50 as `access_log.2.gz`, `access_log.3.gz`, etc.  To parse the last year
51 of those archived logs, use something like:
52
53     $ for i in $(seq 52 -1 2); do awstats.pl -config="${PWD}/awstats.example.conf" -LogFile="gzip -cd example-logs/access_log.${i}.gz |"; done
54
55 After working through the archived logs, you can process the current
56 log file:
57
58     $ awstats.pl -config="${PWD}/awstats.example.conf"
59
60 Once all the logs have been processed, run
61
62     $ awstats.pl -config="${PWD}/awstats.example.conf"
63
64 To generate the report, run
65
66     $ awstats.pl -config="${PWD}/awstats.example.conf" -output
67
68 [AWStats]: http://www.awstats.org/
69
70 [[!tag tags/tools]]
71 [[!tag tags/web]]