2008-01-23

Visitors-利用 web log達成流量統計圖表化

【前言】

[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]

【作業環境】

FreeBSD 6.2-RELEASE

visitors-0.7.0_1

【安裝及設定】

Step1.安裝 visitors 套件

 #cd /usr/ports/www/visitors     //切換至安裝路徑
#make install clean //安裝並清除安裝過程中不必要的檔案

Step2.產生分析圖表

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

  • -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 即可。

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

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

 CPU: Intel(R) Core(TM)2 CPU 6300  @ 1.86GHz (1867.21-MHz 686-class CPU)
real memory = 2146299904 (2046 MB)

以下是測試分析不同行數的 web log 分析速度

 #wc -l 200708.log | awk '{print$1}'
56133 //5.6 萬行
#/usr/local/bin/visitors -A -m 50 200708.log -o html > /home/web/200708.html
--
56133 lines processed in 1 seconds //分析時間花費 1 秒
0 invalid lines, 0 blacklisted referers
#wc -l 2007.log | awk '{print$1}'
318290 //31 萬行
#/usr/local/bin/visitors -A -m 100 2007.log -o html > /home/web/2007.html
--
318290 lines processed in 5 seconds //分析時間花費 5 秒
0 invalid lines, 0 blacklisted referers

Step3.排程

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

 #vi /usr/local/sbin/visitors.sh             //建立 shell 檔內容如下
#!/bin/sh
TODAY=`date +%Y%m%d`
LOG="/home/log/apache"
DES="/home/web"
VISITORS=/usr/local/bin/visitors
SHOW="50"
${VISITORS} -A -m ${SHOW} ${LOG}/${TODAY}.log -o html > ${DES}/${TODAY}.html
#chmod +x /usr/local/sbin/visitors.sh

再來就是設定排程

 #crontab -e
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 のプチ改造]

【Log】

初稿-2008/01/18

2008-01-19

6.3 發公告了

03:24 -!- rafan changed the topic of #bsdchat to: 6.3-R
03:45 <@evi1c> [FreeBSD-Announce] FreeBSD 6.3-RELEASE Available
03:45 <@evi1c> rafan: 手快 (Y)

ref: http://lists.freebsd.org/pipermail/freebsd-announce/2008-January/001167.html

2007-12-09

你有 screen 時而不起的困擾嗎?看看這個吧

00:31 jnlin> puttytray真好用XD
00:34 yhchan> jnlin++
00:34 chinsan> jnlin: puttytray 我覺得不太好用 XD 若有內建 tab 的 putty 會比較好
00:35 jnlin> chinsan: tab!
00:35 jnlin> chinsan: 我是覺得有 screen 就很好用了 XD
00:37 chinsan> jnlin: screen 有時候 -r 或 -x (機率更高) 會當啊...到時候連的一大堆機器都要重來一次..
00:37 superd> 有的時候,還是得開二個 putty ><"
00:38 chinsan> wintabber 則是遇到不同大小的 putty 切換畫面時會怪怪的..
00:40 jnlin> chinsan: 我大概習慣當掉以後去重開了XD
00:41 gslin_csie> chinsan: 會當是因為另外一個 terminal 卡住了,給 sshd 一腳就好
00:43 chinsan> gslin_csie: 原來是這樣 @_@, 下次先試試看
00:43 * chinsan 都 -wipe
00:45 kcwu> 原來如此...
00:46 jnlin> gslin_csie: 有時候是 socket 不見了XD
00:46 gslin_csie> jnlin: 那就給他個 USR1?
00:46 gslin_csie> 還是 CONT?
00:47 yinjieh> 現在 socket 不見我都找一個 screen 裡面的 shell kill -9
00:47 yinjieh> 就回來了
00:48 gslin_csie> 都猜錯了,是 SIGCHLD...
00:48 gslin_csie> http://www4.informatik.uni-erlangen.de/~jnweiger/screen-faq.html
00:48 gslin_csie> "For some unknown reason, the fifo in /tmp/screens/S-myname is gone, and i can't resume my screen session. Is there a way to recreate the fifo?"
00:48 KN16H7> hmmm
00:49 jnlin> gslin_csie++
00:49 jnlin> 下次試試XD
00:49 gslin_csie> 我記得很久前本頻道有人講過啊
00:49 gslin_csie> yinjieh: 我記得明明就是你講的
00:50 chinsan> yinjieh: XD
00:50 yinjieh> gslin_csie: 是我找的沒錯啊 XD

Q: For some unknown reason, the fifo in /tmp/screens/S-myname is gone, and i can't resume my screen session. Is there a way to recreate the fifo?
A: Screen checks the fifo/socket whenever it receives a SIGCHLD signal. If missing, the fifo/socket is recreated then. If screen is running non set-uid the user can issue a 'kill -CHLD screenpid' directly (it is -CHILD on some systems). Screenpid is the process-id of the screen process found in a 'ps -x' listing. But usually this won't work, as screen should be installed setuid root. In this case you will not be able to send it a signal, but the kernel will. It does so, whenever a child of screen changes its state. Find the process-id (shellpid below) of the "least important" shell running inside screen. The try 'kill -STOP shellpid'. If the fifo/socket does not reappear, destroy the shell process. You sacrify one shell to save the rest. If nothing works, please do not forget to remove all processes running in the lost screen session.

所以解法就是送 SIGCHLD 給該 screen PID,那麼 screen 就會自動檢查 fifo/socket。比方該 screen PID 為 5566,那麼拯救 screen 的方是就是 kill -s CHLD 5566 或者 kill -20 5566 亦可。

另外,看不太懂上面那段 kill 是要幹嘛的,可以看看 kill(1) 指令有寫:
Some of the more commonly used signals:
1 HUP (hang up)
2 INT (interrupt)
3 QUIT (quit)
6 ABRT (abort)
9 KILL (non-catchable, non-ignorable kill)
14 ALRM (alarm clock)
15 TERM (software termination signal)

sigaction(2)有更詳細的解釋,
SIGCHLD discard signal child status has changed

或者參考 src/sys/sys/signal.h
#define SIGCHLD 20 /* to parent on child stop or exit */

2007-12-04

經驗

18:01 <@E> A: 剛剛我才到 Beta4 ... -.-a
18:01 <@E> A: 好奇怪的感覺...
18:01 <@A> E: 怎麼說?
18:01 <@E> A: 說不上來的感覺...
18:02 <@A> E: 不過iso還沒出來
18:02 <@E> A: 好像很遠,也好像很近... XD
18:02 <@E> A: 明天再好好來玩玩..
18:04 <@E> A: 從 6.2R 到 7-Beta4 ... 好像沒什麼陣痛... 對,就是這個感覺. XD
18:05 <@A> E: 我可是很痛啊...該死的/
18:06 <@E> A: 我本來預期應該會有陣痛的... @@"
18:11 <@v> E: 你又不是妹, 怎麼會痛.
18:11 <@v> 也不是第一次了
18:16 <@A> @_@
18:17 <@y> 經驗多了以後,大家也比較會僑角度了

2007-11-28

Cronolog 無法處理 Lighttpd Error Log?

Q8.cronolog 無法套用在 lighttpd.error.log 上?

Error Meaage:

裝了 cronolog (每天產生一個 log)後想套用在 Lighttpd access 及 error log 上但啟動 lighttpd 時卻會發生錯誤,說找不到 error log。

#/usr/local/etc/rc.d/lighttpd start
2007-11-28 17:17:22: (log.c.62) opening errorlog '|/usr/local/sbin/cronolog /var/log/%Y_%m_%d-error.log' failed: No such file or directory
2007-11-28 17:17:22: (server.c.945) opening errorlog failed, dying

Ans:

在 google 上找了一下後發現這篇#296 (Can't use cronolog with server.errorlog) - lighttpd - secure, fast, compliant, and very flexible web-server - Trac有說明就是目前使用 cronolog 來處理 lighttpd 的log的話對於 access log 是 ok 的,但若是 error log 則還有點問題,反正分析軟體通常也都只分析 access log 而以,所以就先這樣吧。

#accesslog.filename = "/var/log/lighttpd.access.log" //預設值
accesslog.filename = "|/usr/local/sbin/cronolog /var/log/%Y_%m_%d-access.log" //更改後
server.errorlog = "/var/log/lighttpd.error.log" //預設值

因為 lighttpd 沒有寫入 /var/log 的權限,所以上面的設定還是會有問題例如會跳出 /var/log/2007_11_29-access.log: Permission denied 但又不想把 /var/log 設 owner 為 www所以我把產生的路徑移到例如 /home/log 然後設 owner 為 www 這樣就可順利每天產生 log 了。

accesslog.filename = "|/usr/local/sbin/cronolog /home/log/%Y_%m_%d-access.log"

2007-10-27

義賣 Absolute FreeBSD 第二版首印本

FreeBSD 基金會把 Michael Lucas 捐贈的 Absolute FreeBSD 第二版首印本放在 ebay 這邊義賣,希望能稍微補足還不夠的基金會運作經費。拍賣預計 11/02 結束。

FreeBSD 基金會首頁可以看到今年基金經費籌募狀況

Fundraising meter

2007-09-07

HD移機 on FreeBSD

幾個星期前,機房的AD backup退下來了,剛好這台機子可以替換掉我玩的Celeron 500Mhz的FreeBSD機器,我的想法是HD轉到那台去,開機就會自己抓到了,至少我玩Linux都是這個樣子的...

chwong :Linux "可以"認 label, and 現在很多 distributions 是認 label
chwong :FreeBSD default 是認 device file

但是開機後,出現找不到root file system,就習慣的把指令打上去,mount -a...
把每個partition都打過一次了,還是失敗,懶人懶的上網爬文了,馬上call給學長chwong求救,事情果然很容易就解決了..

-------------------------------------------------------------------------------------
原因:預設root file system為ad0s1a,而新機變為ad1s1a,因為ad0被其它device搶走了..

chwong :你要這麼說也是可以,但實際上是因為 unix 在編硬體編號的時候,是根據 channel 來編的
chwong :在 IDE 介面上面,一個 channel 可以兩個硬碟
chwong :所以假如你在第三個 channel, 第一個硬碟,那編號就是 4 (0 1 2 3 4)

1)開機後出現找不到root file system,因為它並不是在os底下,所以它的語法就不同了..
它下面會有說明,ex:ufs:ad1s1a
通常root file system為ad?s1a,尾數為a。

2)接著會進入single mode,此時你必需再將root重新mount..

chwong :
進 single user mode 的時候 default 只會 mount 成 read-only

3)把/usr mount上,因為軟體是放在/usr底下的,沒mount上,無法使用editor..

4)修改/etc/fstab改成新的代號

5)Finally,save and reboot..

Successed!!