天天看點

使用webalizer分析nginx 通路日志

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等。

下載下傳位址:

<a href="ftp://ftp.mrunix.net/pub/webalizer/webalizer-2.23-05-src.tgz">ftp://ftp.mrunix.net/pub/webalizer/webalizer-2.23-05-src.tgz</a>

[[email protected] webalizer-2.23-05]# tar xf webalizer-2.23-05-src.tgz

[[email protected] webalizer-2.23-05]# ./configure --with-language=chinese

[[email protected] webalizer-2.23-05]# make

6.編譯成功後,會産生一個webalizer可執行檔案,可以将其拷貝到/usr/sbin/目錄下:

[[email protected] webalizer-2.23-05]# ls -l weba*

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

[[email protected] webalizer-2.23-05]# cp webalizer /usr/bin/

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

配置:

上面說過,可以通過指令行配置webalizer,也可以通過配置檔案進行配置,在本文中我們将介紹使用指令行參數進行配置,需要了解配置檔案使用方法的朋友可以參考README檔案,裡面有很詳細的介紹。

可以執行webalizer –h得到所有指令行參數:

[[email protected] 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'

#!/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的設定多了一個空格 而不能分析出來.這點需要仔細排查.

<a href="http://jueshitou.blog.51cto.com/attachment/201105/20/385947_1305885088Hnb2.jpg"></a>

     本文轉自 珏石頭 51CTO部落格,原文連結:http://blog.51cto.com/gavinshaw/569820,如需轉載請自行聯系原作者