正在浏览 awstats 里的文章

Awstats 7.0 新特征

抢沙发

Awstats推出7.0 Beta 版本,该版本最大的更新莫过于添加了graphgooglechartapi插件,该插件调用了google的chart api来创建图表,当然代价就是页面的载入速度更慢了:
awstats_7_1.png
截图1
awstats_7_2.png
截图2

启用graphgooglechartapi插件,只需在站点配置文件中加入:
LoadPlugin="graphgooglechartapi"

==========================
Awstats 7.0 Changelog
- Detect Windows 7.
- Can format numbers according to language.
- More mime types.
- Added geoip_asn_maxmind plugin.
- Geoip Maxmind city plugin have now override file capabilities to complete
missing entries in geoip maxmind database.
- Added graphgooglechartapi to use online Google chart api to build graph.
- Can show map of country to report countries when using graphgooglechartapi.
- Part of codes was change to use more functions and have a cleaner code.
- Added parameter to ignore missing log files when merging for a site on
multiple servers where a single server may not have created a log for a given day.
- Update robots database.

原创文章,转载请注明: 转自 http://salogs.com

为了让awstats分析squid的日志,我们要修改一下它的日志格式.我们先看看squid的默认格式和解释吧.

logformat squid  %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt

解释如下:
Seconds since epoch; subsecond time (milliseconds);  Response time (milliseconds); Client source IP address;  Squid request status (TCP_MISS etc); HTTP status code; Reply size including HTTP headers;  Request method (GET/POST etc) ; Request URL;  User name;  Squid hierarchy status (DEFAULT_PARENT etc);  Client FQDN;  MIME content type

下面看看要怎么样修改,awstats才能认识和分析squid的日志

squid: /etc/squid/squid.conf
代码:

logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh %{host}>h
access_log /var/log/squid/access.log combined

awstats: /etc/awstats/awstats.conf.local
代码:

LogFormat = "%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot %other %virtualname"
LogFile="/var/log/squid/access.log"

关键点: squid 的日志需要加上虚拟主机名: %{host}>h awstats的读取参数指出 %virtualname 还有一种方法,我觉得也是比较理想的,直接修改apache的日志格式:

原:
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

修改为:
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""combined

这样也可以将apache的日志转为正常的日志。

转载自:扶凯[http://www.php-oa.com]

用处:

1.用lvs之后,放了多台前端用的Web Server,每台Server有各自的日志.我们分开使用分析软件分析和检查是非常困难的,所以我们使用合并的方法.
2.多个域名,日志分开,使用awstats之类的分析软件进行分析很麻烦,所以需要合并
3.使用google的软件来做sitemap之类的应用,检查也会非常麻烦,所以需要合并
4.象多个节点的CDN日志,要进行流量统计和分析需要合并
5.因为日志文件过大,一个服务器生成多个日志文件.象access_log.1、access_log.2、access_log.3…以此类推,所以要合并.
等等…..

问题
对合并,进行日志排序最麻烦的一个问题就是,容易在跨天过程中生成的非正常数据.用一个前辈的话,这些不正常的日志,对awstats之类,就象吃了虫子一样,还有可能冲掉你以前的所有数据。

解决方法1(多谢东东):
在分析日志前,使用
sort -m -t " " -k 4 -o log_all log1 log2 log3
注释:
-m: 使用 merge优化算法

解决方法2:
使用 awstats 内建的工具logresolvemerge.pl 来合并日志 ,方法非常容易,主要是更改网站的设定档就好了,编辑 /etc/awstats/awstats.php-oa.conf
找到 LogFile 的地方,原来预设单个 log 的设定如下:

LogFile="/var/log/httpd/access_log"(原设置)

修改成
LogFile="/usr/local/awstats/tools/logresolvemerge.pl /var/log/httpd/access_log* |" (合并分析新的设置)

如上,其实只要 logresolvemerge.pl 的路径还有日志的路径及使用匹配来设置即可,记的后面加一个"|"。注意上面我是要合并 access_log.1、access_log.2、access_log.3 的日志,要是你的日志名为别的,记的使用匹配符来匹配你要一起合并分析的日志.
另外.默认logresolvemerge.pl 是放在 awstats 安装路径的 tools 里面,比如我们的 awstats 是装在/usr/local/awstats 里面,所以完整路径就是 /usr/local/awstats/tools/logresolvemerge.pl 。

编辑保存后,再来执行更新记录的程序即可,如:
#/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=xxx -update

再来进去您的网址就可以看到合并后输出的结果了,如:

http://www.yoursite.com/awstats/awstats.pl?config=xxx

转载自:扶凯[http://www.php-oa.com]


简介
AWStats,全名为 Advanced Web Statistics,是一套免费功能强大并支援多国语言的工具软件,专门用来分析Web.Streaming.FTP或Mail服务器的统计资料,并可产生统计报表,显示用户端连线至网站存取网页的日志信息。它可以分析许多主要服务器的日志文件,如 Apache 的日志文件 (NCSA combined/XLF/ELF 日志格式或者 common/CLF 日志格式)、WebStar、IIS (W3C 日志格式) 以及许多其它的 Web、Proxy、Wap、Streaming 服务器、Mail 服务器及部份 FTP 服务器。
AWStats 与其它统计分析软件(Analog、Webalizer、HitBox…)相较之下,可以产生更多样的纪录,并做更详细的分析。你可以到这里查看比较著名的分析工具 (AWStats、Analog、Webalizer...)的功能及差异性的功能比较表。
AWStats 是免费的 GPL (GNU General Public License) 授权软件,你可以查看 license chart 看哪些是可以或不能做的。
AWStats 是以 Perl 透过指令列的方式执行,但也可以从浏览器透过 CGI 的方式来做即时更新的动作,因此请在安装之前确认系统中已安装 Perl 程序或组件,并启动 CGI 的执行权限。

下载
访问 http://awstats.sourceforge.net/#DOWNLOAD 下载最新的稳定版本或者最新的测试版。本文使用最新的测试版来做介绍

wget http://awstats.sourceforge.net/files/awstats-6.95.tar.gz


安装前准备工作
yum -y install php php-devel php-eaccelerator httpd httpd-devel perl perl-URI perl-Geo-IP perl-Geo-IP-PurePerl perl-Geo-IPfree geoip perl-Net-XWhois


系统环境

CentOS     5.3
Apache     2.2.3
PHP        5.1.6
Awstats    6.95

安装前的规定

/usr/local/awstats            awstats的安装路径
/usr/local/awstats/wwwroot    这目录下的文件就是用户通过浏览器访问到的页面
/etc/awstats                  awstats的站点配置路径
/usr/local/awstats/log        awstats所要分析的日志路径 需要手工创建
/usr/local/awstats/datadir    awstats的db路径 需要手工创建

安装
# sed -i "265 s/#ServerName www.example.com:80/ServerName localhost:80/g" /etc/httpd/conf/httpd.conf
# tar -xvzf awstats-6.95.tar.gz -C /usr/local/
# mv awstats-6.95/ awstats
# mkdir awstats/{log,datadir}
# chown apache.apache datadir/ -R # 使用web界面更新数据信息该目录必须可写
#
cd awstats/tools
# ./awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 1.8) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----&gt; Running OS detected: Linux, BSD or Unix
-----&gt; Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
&gt;/etc/httpd/conf/httpd.conf 由于apache是yum安装的故其主配置文件在这里
 
输入完apache配置路径后,配置程序会将awstats的配置信息写入到apache主配置文件中。
-----&gt; Check and complete web server config file '/etc/httpd/conf/httpd.conf'
Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
Add '' directive
AWStats directives added to Apache config file.
-----&gt; Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.
 
这一步是询问是否要创建一个标准的awstats配置文件。
-----&gt; Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? Y
 
定义配置文件
-----&gt; Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
&gt; www.myweb.com
 
定义配置文件路径
-----&gt; Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
&gt; 直接回车即可,按照默认的路径/etc/awstats 
 
这一步说明刚刚创建的www.myweb.com的配置文件路径
-----&gt; Create config file '/etc/awstats/awstats.www.myweb.com.conf'
Config file /etc/awstats/awstats.www.myweb.com.conf created.
 
修改完配置文件后 重启apache服务
-----&gt; Restart Web server with '/sbin/service httpd restart'
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
 
将更新进程加入到计划任务中。该脚本不支持写入计划任务的操作,需要手动完成
-----&gt; Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.myweb.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...
 
简单的配置文件已经完成,这个配置文件还需要手动设置一些变量,且第一次手动来执行更新脚本。
A SIMPLE config file has been created: /etc/awstats/awstats.www.myweb.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.myweb.com' with command:
&gt; perl awstats.pl -update -config=www.myweb.com
You can also read your statistics for 'www.myweb.com' with URL:
&gt; http://localhost/awstats/awstats.pl?config=www.myweb.com
Press ENTER to finish...


系统集成

# cd /usr/local/bin
# ln -s /usr/local/awstats/tools/*.pl .

配置awstats


至此为止,利用awsats_configure.pl脚本进行安装的工作已经完成,接下来手动编辑配置文件,修改如下选项
# vi /etc/awstats/awstats.www.myweb.com.conf
LogFile="/var/log/httpd/mylog.log"
修改为
LogFile="/usr/local/awstats/log/www.myweb.com.log"
DirData="/usr/lib/awstats"
修改为
DirData="/usr/local/awstats/datadir"
AllowToUpdateStatsFromBrowser=0
修改为
AllowToUpdateStatsFromBrowser=1
或直接执行下面sed命令完成修改

sed -i -e "51 s/LogFile=\"\/var\/log\/httpd\/mylog.log\"/#LogFile=\"\/var\/log\/httpd\/mylog.log\"\nLogFile=\"\/usr\/local\/awstats\/log\/www.myweb.com.log\"/" -e "204 s/DirData=\"\/var\/lib\/awstats\"/#DirData=\"\/var\/lib\/awstats\"\nDirData=\"\/usr\/local\/awstats\/datadir\"/" -e "240 s/AllowToUpdateStatsFromBrowser=0/AllowToUpdateStatsFromBrowser=1/" /etc/awstats/awstats.www.myweb.com.conf

执行完上面的命令后,配置文件的相应行被修改成了如下内容:

LogFile="/var/log/httpd/mylog.log"

LogFile="/usr/local/awstats/log/www.myweb.com.log"

#DirData="/var/lib/awstats"

DirData="/usr/local/awstats/datadir"

#AllowToUpdateStatsFromBrowser=0

AllowToUpdateStatsFromBrowser=1

将www.myweb.com的日志复制到配置awstats的机器中,并更名为www.myweb.com.log复制到/usr/local/awstats/log目录下。

# cp access.log /usr/local/awstats/log/www.myweb.com.log

# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.myweb.com

Create/Update database for config "/etc/awstats/awstats.www.myweb.com.conf" by AWStats version 6.95 (build 1.932)
From data in log file "/usr/local/awstats/log/www.myweb.com.log"...
Phase 1 : First bypass old records, searching new record...
Direct access to last remembered record has fallen on another record.
So searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 111879
Found 166 dropped records,
Found 43153 corrupted records,
Found 33 old records,
Found 68527 new qualified records.

# crontab -e

5 2 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.myweb.com

如果有多个站点可以使用awstats提供的批量更新状态的程序

5 2 * * * /usr/local/awstats/tools/awstats_updateall.pl now 2>&1>/dev/null

awstats_updateall.pl 使用方法和参数如下:

# ./awstats_updateall.pl --help

----- awstats_updateall 1.0 (build 1.15) (c) Laurent Destailleur -----
awstats_updateall 程序会更新所有 AWStats 配置文件(awstats.model.conf除外)
因此可以设置一条简单的cron/scheduler 任务。程序扫描的目录默认为/etc/awstats.
 
用法: awstats_updateall.pl now [options]
 
选项:
# 指定awstats.pl的文件路径
-awstatsprog=pathtoawstatspl 
 
# 配置文件路径。默认为/etc/awstats
-configdir=directorytoscan
 
# 需要排除的配置文件。awstats.model.conf 永久排除
-excludeconf=conftoexclude[,conftoexclude2,...]

重新启动apache

# service httpd restart

访问awstats页面

设置awstats安全登录
# htpasswd -c /etc/httpd/awstatspass awstats

New password:                     密码:******

Re-type new password:

Adding password for user awstats

# vi /etc/httpd/conf/httpd.conf

?View Code APACHE
1
2
3
4
5
6
7
8
9
10
11
12
13
Options none
AllowOverride None
Order allow,deny
Allow from all
#修改为
Options IncludesNoExec
AuthType Basic
AuthName "Awstats Web Login"
AuthUserFile "/etc/httpd/awstatspass"
Require User awstats
AllowOverride None
Order allow,deny
Allow from 192.168.0.0/16

# service httpd restart
再访问页面

提示输入密码方可进入web页面

附录
更新历史
2009/06/09    ZhouYueQiu First release
2009/07/14    ZhouYueQiu 修正DirData参数错误,增加了。更新所有配置文件的命令。