写于:2003/04 最后更新:02/11/2004 17:02:02
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明
http://www.chedong.com/tech/awstats.html
关键词:awstats web log analysis apache iis 日志 分析 open source
内容摘要:AWStats的使用简介和配置一些改进说明。
附:包含了针对Google UTF-8查询和国内主要门户网站定义补丁的AWStats 6.0 补丁下载(解包后覆盖原程序目录即可)
日志统计系统在站点的用户行为分析中扮演了重要的角色,尤其是对于来自搜索引擎的关键词访问统计:是很有效的用户行为分析数据来源。随着互联网多年的发展,WEB日志统计工具已经越来越成熟,功能也越来越丰富。其中有很多是开放源代码的, AWStats就是其中非常优秀的一款。
AWStats是最近发展很快的一个基于Perl的WEB日志分析工具。相对于另外一个非常优秀的开放源代码的日志分析工具Webalizer,AWStats的优势在于:
更多与其他工具:Webalizer, analog的比较请参考:
http://awstats.sourceforge.net/#COMPARISON
AWStats的运行模式是这样的:
以下是2个针对单个站点日志统计例子:
一个是在GNU/Linux上通过CGI方式的输出,
一个是在Windows 2000上的基于静态页面的导出
GNU/Linux:tar zxf awstats-version.tgz
#部署awstats cgi程序到/path/to/apache/cgi-bin/awstats
mv awstats-version/wwwroot/cgi-bin /path/to/apache/cgi-bin/awstats
#把图标icon目录复制到WEB发布目录下:/path/to/apache/htdocs/icon/
Windows 2000: 直接解包,然后移动到D:AWStats目录下
把图标icon目录复制到IIS的发布目录下:inetpub/icon
AWStats的主程序awstats.pl会自动根据站点名调用相应站点的配置文件:awstats.sitename.conf
比如:运行./awstats.pl -config=chedong 调用的就是同目录下的 awstats.chedong.conf 配置文件;
如果没有指定-config,还会找当前目录下的awstats.conf或者/etc/awstats.conf作为缺省配置文件。
所以最好把缺省的awstats.model.conf 重命名成 awstats.yoursite.conf;比如:awstats.chedong.conf,
对于多个站点的统计,AWStats的配置文件包含功能还是非常有用的,我们可以把通用的配置放在一个文档中,然后用(5.4版本以后开始支持) Include配置将通用配置包含在各个具体配置文件的头部,然后用其他配置覆盖通用配置中的相应属性,比如:
Include="common.conf"
LogFile="/path/to/bbs/access_log"
SiteName="bbs.chedong.com"
对于在GNU/Linux上统计Apache日志只需修改:LogFile SiteDomain这2个选项
GNU/Linux上:crontab -e: 每天8点10分运行
#update awstats
10 8 * * * (cd /path/to/apache/cgi-bin/awstats/; ./awstats.pl -update -config=chedong)
Windows 2000上:设置每天8点10分运行
D:Perlinperl.exe d:AWStats oolsawstats_buildstaticpages.pl -update -config=chedong -lang=cn -dir=c:inetpubawstats -awstatsprog=d:awstatswwwrootcgi-binawstats.pl
AWStats自带了一个批处理工具:tools/awstats_updateall.pl,可以批量地遍历一个目录下所有地配置文件并运行统计。因此剩下的工作就主要是日志的同步问题了。
针对多个站点,很多配置选项是重复的,如果每个配置文件都修改维护起来会很麻烦,AWStats从5.4版本开始提供了配置文件包含的功能,所以我们可以配置一个通用配置,比如:common.conf
然后其他站点的配置设置为:可以通过后面的选项覆盖和缺省不一致的配置。
awstats.bbs.chedong.conf
Include "chedong.common.conf"
LogFile "/path/to/bbs_log"
SiteName "bbs.chedong.com"
awstats.www.chedong.conf
Include "chedong.common.conf"
LogFile "/path/to/www_log"
SiteName "www.chedong.com"
HostAliases="chedong.com"
在Awstats 5.5以后中已经加入了针对中文主要搜索引擎的定义:这里是补充后的完整列表(包括了主要门户搜索和搜索门户)
62c60
< "baidu.com","search.sina.com","search.sohu.com",
---
> "baidu.com","sina.com","3721.com","163.com","tom.com","sohu.com",
153c144
< "baidu.com","word=", "search.sina.com", "word=", "search.sohu.com","word=",
---
> "baidu.com","word=", "sina.com", "word=", "3721.com", "name=","163.com","q=","tom.com","word=","sohu.com","word=",
250c234
< "baidu.com","Baidu", "search.sina.com","Sina", "search.sohu.com","Sohu",
---
> "baidu.com","Baidu", "sina.com","Sina", "3721.com","3721","163.com","NetEase","tom.com","Tom","sohu.com","Sohu",
对Google的Unicode查询还是需要一些查询补丁:
因为Google对于Windows 2000以上的IE浏览器缺省发送的查询都是UTF-8格式的,而其他搜索引擎大部分使用的是系统本地编码:GB2312,因此需要将查询URI解码后,还要根据是否使用UTF-8进行到GB2312的转码,否则同样的单词会在统计中留有UTF-8和GB2312两条记录。
我增加了以下函数用于Google UTF-8字符的解码和类似于“xc4xbexd7xd3xc3xc0”这样查询的解码
sub Utf8_To_Ascii {
my $string = shift;
my $encoding = shift;
# change xc4xbexd7xd3xc3xc0 into %c4%be%d7%d3%c3%c0
$string =~ s/\x(w{2})/%1/gi;
# uri unescape
$string = uri_unescape($string);
if ( $string =~ m/^([x00-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]|[xe1-xef][x80-xbf][
x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf])*$/ )
{
$string = decode("utf-8", $string);
$string = encode($encoding, $string);
}
# trim space
$string =~ s/^s+//;
$string =~ s/s+$//;
# reverse "+", ";" to space
$string =~ s/;+//g;
$string =~ s/s+/+/g;
#print $string."
";
return $string;
}
GeoIP 和 Geo::IPfree(awstats 5.5+)
GeoIP和Geo::IPfree都免费的是国家/IP的影射表,比通过DNS反相解析域名得到的统计准确,而且速度快。GeoIP的API都是免费的,缺省库是免费的,收费的是它的数据更新服务。Geo::IPfree不仅代码是公开的,而且库数据也是公开的,因此可以自己定制,我曾经设想做一个中国城市到IP的映射。
GeoIP安装:
先下载C库:GeoIP C解包后
%./configure; make
#make install
然后下载Perl库:GeoIP Perl解包后
%perl MakeFile.PL; make
#make install
Geo::IPfree安装:
下载Geo::IPfree解包后
%perl Makefile
%make
#make install
配置:通过在配置文件中启用插件GeoIP或者Geo::IPfree
AWStats
http://awstats.sourceforge.net/
Webalizer
http://www.webalizer.org/
日志分析工具
http://directory.google.com/Top/Computers/Software/Internet/Site_Management/Log_Analysis/
商业日志统计/分析工具
http://directory.google.com/Top/Computers/Software/Internet/Site_Management/Log_Analysis/Commercial/
多站点的日志合并统计:
http://www.chedong.com/tech/rotate_merge_log.html
日志统计对于分析搜索引擎对站点的影响具有非常重要的意义
http://www.chedong.com/tech/google.html
AWStats 本身也包含了很多插件,包括将多个站点的统计再次汇总输出,IIS日志时间转换,URL的标题映射等http://awstats.sourceforge.net/awstats_contrib.html
原文出处:<a href="http://www.chedong.com/tech/awstats.html">http://www.chedong.com/tech/awstats.html</a>
了解这些字:的的意思 日的意思 志的意思 分的意思 析的意思 工的意思 具的意思