您的位置:首页 > 运维架构 > Nginx

使用webalizer分析nginx 访问日志 推荐

2011-05-20 17:51 761 查看
webalizer是一个高效的、免费的web服务器日志分析程序。其分析结果以HTML文件格式保存,从而可以很方便的通过web服务器进 行浏览。Internet上的很多站点都使用webalizer进行web服务器日志分析。Webalizer具有以下一些特性:

1. 为是用C写的程序,所以其具有很高的运行效率。在主频为200Mhz的机器上,webalizer每秒钟可以分析10000条记录,所以分析一个40M大小的日志文件只需要15秒。

2. webalizer支持标准的一般日志文件格式(Common Logfile Format);除此之外,也支持几种组合日志格式(Combined Logfile Format)的变种,从而可以统计客户情况以及客户操作系统类型。并且现在webalizer已经可以支持wu-ftpd xferlog日志格式以及squid日志文件格式了。

3. 支持命令行配置以及配置文件。

4. 可以支持多种语言,也可以自己进行本地化工作。

5. 支持多种平台,比如UNIX、linux、NT, OS/2 和 MacOS等。

下载地址:

ftp://ftp.mrunix.net/pub/webalizer/webalizer-2.23-05-src.tgz
[root@Www.wangyuelou.org webalizer-2.23-05]# tar xf webalizer-2.23-05-src.tgz

[root@Www.wangyuelou.org webalizer-2.23-05]# ./configure --with-language=chinese

[root@Www.wangyuelou.org webalizer-2.23-05]# make

6.编译成功后,会产生一个webalizer可执行文件,可以将其拷贝到/usr/sbin/目录下:
[root@Www.wangyuelou.org webalizer-2.23-05]# ls -l weba*

-rwxr-xr-x 1 root root 167563 May 20 15:16 webalizer

[root@Www.wangyuelou.org webalizer-2.23-05]# cp webalizer /usr/bin/

弄完之后就可以配置webalizer了.

配置:

上面说过,可以通过命令行配置webalizer,也可以通过配置文件进行配置,在本文中我们将介绍使用命令行参数进行配置,需要了解配置文件使用方法的朋友可以参考README文件,里面有很详细的介绍。

可以执行webalizer –h得到所有命令行参数:
[root@Www.wangyuelou.org webalizer-2.23-05]# webalizer -h

Usage: webalizer [options] [log file]

-h = print this help message

-V = print version information

-v = be verbose

-d = print additional debug info

-F type = Log type. type= (clf | ftp | squid | w3c)

-f = Fold sequence errors

-i = ignore history file

-p = preserve state (incremental)

-b = ignore state (incremental)

-q = supress informational messages

-Q = supress _ALL_ messages

-Y = supress country graph

-G = supress hourly graph

-H = supress hourly stats

-L = supress color coded graph legends

-l num = use num background lines on graph

-m num = Visit timout value (seconds)

-T = print timing information

-c file = use configuration file 'file'

-n name = hostname to use

-o dir = output directory to use

-t name = report title 'name'

-a name = hide user agent 'name'

-r name = hide referrer 'name'

-s name = hide site 'name'

-u name = hide URL 'name'

-x name = Use filename extension 'name'

-O name = Omit page 'name'

-P name = Page type extension 'name'

-I name = Index alias 'name'

-K num = num months in summary table

-k num = num months in summary graph

-A num = Display num top agents

-C num = Display num top countries

-R num = Display num top referrers

-S num = Display num top sites

-U num = Display num top URLs

-e num = Display num top Entry Pages

-E num = Display num top Exit Pages

-g num = Group Domains to 'num' levels

-X = Hide individual sites

-z dir = Use country flags in 'dir'

假设,web服务器的主机名www.wangyuelou.org,统计站点为op.wangyuelou.org,访问日志为/app/log/wangyuelou.access.log.我们将分析结果输入到/home/wwwroot/log(统计站点的根目录)下面.我们可以建立如下脚本.
#!/usr/bin

run=/usr/sbin/webalizer

$run -F clf -p -n '' -t 'www.wangyuelou.org' -o /home/wwwroot/log /app/log/wangyuelou.access.log

-F clf 指明我们的web日志格式为标准的一般日志文件格式(Common Logfile Format)

-p 指定使用递增模式,这就是说每作一次分析后,webalizer会生产一个历史文件,这样下一次分析时就可以不分析已经处理过的部分。这样我们就可以在短时间内转换我们的日志文件,而不用担心访问量太大时日志文件无限增大了。

-n “ “ 指定服务器主机名为空,这样输出结果会美观一些。

-t “www.test.com” 指定输出结果标题。

-o 指定输出目录

/var/log/httpd/access_log:指定日志文件

测试
[root@www log]# $run -F clf -p -n '' -t 'www.wangyuelou.org' -o /home/wwwroot/log /app/log/Noname1.txt

Webalizer V2.23-05 (Linux 2.6.18-238.9.1.el5xen x86_64) English

Using logfile /app/log/Noname1.txt (clf)

Creating output in /home/wwwroot/log

History file not found...

Previous run data not found...

Saving current run data... [04/07/2011 11:01:08]

Generating report for April 2011

Saving history information...

Generating summary report

42 records in 1 seconds, 42/sec

分析的是nginx的日志,可能会因为nginx的设置多了一个空格 而不能分析出来.这点需要仔细排查.



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息