搜索
熱搜: 活動 交友 discuz
查看: 3356|回復: 0
打印 上一主題 下一主題

[Linux] 【CentOS】visitors-利用ApacheLog達成流量統計圖表化

[複製鏈接]
跳轉到指定樓層
1#
發表於 2008-3-7 00:45:59 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
【前言】

[Visitors - fast web log analyzer] 設計為可快速分析 Linux、Windows、Unix-link 等架設 Web 伺服器的 Log,使用方式很簡單只要使用命令列並指定 Log 名稱及輸出流量分析報告格式 (Txt / Html) 即可,因此很適合線上即時查看流量。

Visitors 特色如下

* 不需安裝,每秒可處理 150,000 行 (視機器效能而定,但至少比其它分析軟體快多了)
* 設計上採用指令模式並可輸出 (Txt / Html),因此使用 SSH 登入主機時能夠非常方便且即時查看流量
* 從 Visitors v0.3 以後便支援即時統計、遊客流量統計
* 可清鬆指定產生的流量分析報表項目,相對應參數請參考 [Visitors on line documentation]
* Visitors 為可攜式 C 語言程序,因此可方便使用在不同的系統中。
* 產生的 HTML 報表並不包含圖片或外部的 CSS,因此能方便的將報表透過電子郵件來寄送。
* Visitors 為使用 GPL 授權的自由軟體,所以使用它並不用付費,如果您有興趣想訂製符合您需要的報表歡迎與原作者連絡 antirez (at) invece (dot) org

[Visitors - on line documentation for 0.7]

[Visitors 官網 ScreenShot]

【作業環境】

CentOS 5.1 (Linux 2.6.18-53.1.4.el5)

visitors-0.7

gcc-c++-4.1.2-14.el5

【安裝及設定】

Step1.下載 visitors 套件
  1. #wget [url]http://www.hping.org/visitors/visitors-0.7.tar.gz[/url]     //下載 visitors-0.7.tar.gz
  2. #tar zxvf ~/visitors-0.7.tar.gz                             //解?#125; visitors 壓縮檔
複製代碼


Step2.產生 visitors 執行檔

若無安裝 C+ compiler 就利用 yum -y install gcc-c++ 安裝吧,否則等一下將無法產生 visitors 執行檔。

  1. #rpm -qa gcc-c++                        //確?#123;是否安裝 C+ compiler
  2. gcc-c++-4.1.2-14.el5
複製代碼


產生 visitors

  1. #cd ~/cd visitors_0.7
  2. #make
  3. cc -c -O2 -Wall -W -g  visitors.c
  4. cc -c -O2 -Wall -W -g  aht.c
  5. cc -c -O2 -Wall -W -g  antigetopt.c
  6. cc -c -O2 -Wall -W -g  tail.c
  7. cc -o visitors -O2 -Wall -W -g visitors.o aht.o antigetopt.o tail.o
  8. #cp visitors /usr/local/bin/           //複製執行檔至 /usr/local/bin 下
複製代碼


Step3.產生分析圖表

接下來就是開始分析報表吧。

* -A:分析所有報表項目
* -m 10:項目最多顯示 10 行 (Requested pages、Requested images and CSS...)
* Web Log:200801.log
* -o html:輸出的報表格式
* /home/web/200801.html 為報表輸出的路徑及檔案名稱

若在你的 web log 中有您不想分析的網站時 (例如自已的網站),可加上參數 ex. -P http://your.site.com 即可。

  1. #/usr/local/bin/visitors -A -m 10 200801.log  -o html > /home/web/200801.html
  2. --
  3. 7055 lines processed in 1 seconds
  4. 0 invalid lines, 0 blacklisted referers
複製代碼


我測試一下我使用的機器處理效能,大概是每秒 10.6 萬行左右。

  1. CPU0: Intel(R) Xeon(R) CPU            5130  @ 2.00GHz *2
  2. Mem:   2075284k total  
複製代碼


以下是測試分析不同行數的 web log 分析速度
  1. #wc -l 200708.log | awk '{print$1}'
  2. 56133                                       //5.6 萬行
  3. #/usr/local/bin/visitors -A -m 50 200708.log -o html > /home/web/200708.html
  4. --
  5. 56133 lines processed in 1 seconds          //分析時間花費 1 秒
  6. 0 invalid lines, 0 blacklisted referers
  7. #wc -l 2007.log | awk '{print$1}'
  8. 318290                                      //31 萬行
  9. #/usr/local/bin/visitors -A -m 100 2007.log -o html > /home/web/2007.html
  10. --
  11. 318290 lines processed in 3 seconds         //分析時間花費 3 秒
  12. 0 invalid lines, 0 blacklisted referers
複製代碼


Step4.排程

因為我的 web log 都是每天產生的,所以就寫個簡單的 shell 然後排程執行吧。

  1. #vi /usr/local/sbin/visitors.sh             //建立 shell 檔內容如下
  2. #!/bin/sh
  3. TODAY=`date +%Y%m%d`
  4. LOG="/home/log/apache"
  5. DES="/home/web"
  6. VISITORS=/usr/local/bin/visitors
  7. SHOW="50"
  8. ${VISITORS} -A -m ${SHOW} ${LOG}/${TODAY}.log -o html > ${DES}/${TODAY}.html
  9. #chmod +x /usr/local/sbin/visitors.sh
複製代碼


再來就是設定排程

  1. #crontab -e
  2. 55 23 * * * /usr/local/sbin/visitors.sh       //每天 23:55 執行
複製代碼


【參考】

[Visitors - fast web log analyzer]

[Visitors, on line documentation for 0.7]

[Visitors - ScreenShot]

[2007-03-06 - IT四重奏]

[1秒で10万行を処理するフリーの超高速なログ解析ソフト「Visitors」 - GIGAZINE - IT四重奏]

[GIS Notes by Rupert » Blog Archive » HTTP access_log analysis]

[えせSEの1日1Hack : 2005-08-17]

[Birds Of a Feather | ログ解析ツール Visitors のプチ改造]

[HowtoForge Forums - Notes for CentOS 4.1 install Archive]

[HowtoForge Forums - CentOS 4.4 ~ cc: Command not found]

【Me FAQ】

Q1.make: cc: Command not found?

Error Meaage:

當執行 make 欲產生 visitors 執行檔時發生錯誤 make: cc: Command not found?

  1. #make
  2. cc -c -O2 -Wall -W -g  visitors.c
  3. make: cc: Command not found        
  4. make: *** [visitors.o] Error 127
複製代碼


Ans:

在 Google 上找到這篇[HowtoForge Forums - CentOS 4.4 ~ cc: Command not found],原因是因為機器沒有裝 C compiler 所以就無法順利執行了。(The C compiler is missing on your server. Install the GCC packages) 安裝 gcc-c++ 套件後就可以順利產生了。

  1. #yum -y install gcc-c++
複製代碼
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

本論壇為非營利之網路平台,所有文章內容均為網友自行發表,不代表論壇立場!若涉及侵權、違法等情事,請告知版主處理。


Page Rank Check

廣告刊登  |   交換連結  |   贊助我們  |   服務條款  |   免責聲明  |   客服中心  |   中央分站

手機版|中央論壇

GMT+8, 2026-5-26 11:44 , Processed in 0.044735 second(s), 17 queries .

Powered by Discuz!

© 2005-2015 Copyrights. Set by YIDAS

快速回復 返回頂部 返回列表