piwik fluentd

23
Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP) Piwik – fluentd OSC 2014 Tokyo/Fall 日本 Piwik ユーザー会 やまちゃん [email protected]

Upload: piwikjapan

Post on 10-Jul-2015

558 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

Piwik – fluentd OSC 2014 Tokyo/Fall

日本 Piwik ユーザー会 やまちゃん

[email protected]

Page 2: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

• 日本 Piwik ユーザー会 http://piwikjapan.org/

• SourceForge.JP http://sourceforge.jp/projects/piwik-fluentd/

すでに公開しています

細かい設定はサイトを見てください

Page 3: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

Piwik Version 2.6.0 ~ 2.8.0

(2.8.0 は 2014/10/15 リリース)

最新バージョンに対応しています

Page 4: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

Здравствуйте. Меня зовут Ямачан.

Спасибо за посещать OSC и нашу лекцию.

(ロシア語)

自己紹介

Page 5: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

Piwik-fluentd ってなにするの?

ちょっとながいけど・・・

apache のログを Piwik にとりこみます

fluentd 経由で

ついでに日本語化問題を解決

こんなところでしょうか。

Page 6: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

Piwik を選んだ理由

• Urchin のサポート期限切れてる

– わかっているけど Urchin の数値が実績になっとる

• ID 分けわけなきゃいかん

– サイトごとに担当者が違う

• ボット込の集計が必要

– Urchin の前は EIQ Log analyzer 使ってて... Urchin でも悪しき習慣は引き継ぎ

– ボット込はログからとるしかない

– Open source でログが取り込みるのは Piwik だけ

• 他もあるけど開発はだいぶ前に終了

Page 7: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

import_logs.py

• Piwik のログ取り込みプログラムです

– piwik/static/misc/log-analytics/import_logs.py

• これだけ Python (他は PHP)

• Piwik API 経由でログを Piwik へ

• Apache (urchin 形式含む), NGiИХ, IIS

– Urchin 形式 = combind + cookie

• とはいっても cookie は単に捨てられるだけ

LogFormat "%h %l %u %t ¥"%m %!414U%!414q %H¥" %>s %b ¥"%{Referer}i¥"

¥"%{User-Agent}i¥" ¥"%{Cookie}i¥"" urchin

Page 8: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

構成

Firewall

Web サーバーn

HTTP Server + fluentd(送)

Piwik

DB

RDBMS Server MySQL5.5 Fujitsu RX200 S8 32G SAS

HTTP Server + fluentd(受) 4G 4vCPU

Web サーバー1

HTTP Server + fluentd(送)

Web サーバー2

HTTP Server + fluentd(送)

Internet

Page 9: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

ログを取り込んでみたものの...

• 各サイトから、ログを送り込まなきゃならん

– Urchin だと、FTP で勝手にとってくる機能がある

• 集計プロセスでメモリ馬鹿食い

– import_logs.py を実行後に、集計プロセスを実行しないといろんな数値がでない

• 具体的には console core:archive

• 取り込んだログファイルを識別したい

– スケジュール通りにいかんときもあるでしょうよ

• ローカルタイムが GMT になってしまう

Page 10: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

じゃあ作るか

• 各サイトから、ログを送り込まなきゃならん

– fluentd を使う

• 集計プロセスでメモリ馬鹿食い

– 現状、どうにもならん

– でもちょくちょく実行ですればなんとかなるかも

• 取り込んだログファイルを識別したい

– 難しく考えず make でいいじゃないか

• ローカルタイムを JST にする

• Python しらんけど

Page 11: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

fluentd 利点

• サーバークライアント通信断でも自動再開

• 時間、サイズでお好きなようにログ分割

– ただし JSON なのよ

• import_logs.py って NGiИХ ログが取り込める

– これって JSON じゃん

– ちょっと弄れば fluentd も取り込めるんじゃない ?

Page 12: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

しくみ(1)

• ディレクトリ構成

/your_own_path/fluentd/

├── bin (fluentd 対応の import_logs.py、シェルスクリプト)

├── exclude (取り込んではいけない URL パスが書かれたファイルを格納)

├── log (piwik/console core:archive のログ)

└── td-agent (各サイト毎アクセスログディレクトリ)

├── site1 (Web サイト 1 のアクセスログ、fluentd で放り込む)

├── site2 (Web サイト 2)

├── site3 (Web サイト 3)

└── siteN (Web サイト N)

Page 13: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

しくみ(2)

• site[1..N] に fluentd からの log を放り込む

– fluentd の設定は sourcefogre 見てください

– fluentd でログが転送され分割されます

• だいたい 15M バイト毎

• fluentd の設定でどうにでもなります

– 複数サイトも fluentd で楽勝

Page 14: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

しくみ(3)

• cron で一定時間毎にバッチ

– 取り込み完了後に .archive ファイルを作る

• ついでに import_logs.py の実行結果を格納

– 取り込み完了か否かは make にまかせる

• 未集計のみ import_logs.py にログを渡す

– 集計プロセスを実行

• これをやっとかないと、いろんな数値がでない

• 一つの log ファイル毎ではなく最後に一回

Page 15: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

import_logs.py を直す

• Apache fuentd JSON 形式を読めるように

• ローカル時間を JST にしない

• 日本からアクセスされているようにする

• GET, POST のみ取り込むようにする

– 現時点では HEAD など全部取り込む

– 本家にもリクエストがあがっているんだけど 未だ対応なし

Page 16: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

import_logs.py を拡張する

• Urchin に合わせるためにオプションを追加

– ページビューから除外するファイルの拡張子

– ページビューに含むファイルの拡張子

– RSS として .xml を使っていれば強烈に影響

Pwik 2.6.1,2.7.0 --static-extensions-include=jpe,json --static-extensions-exclude=xml --download-extensions-include=img,iso --download-extensions-exclude=asx,xml,pdf,xls,doc,ppt Pwik 2.8.0 --static-extensions-include=jpe,json --static-extensions-exclude=xml --download-extensions-include=img,iso --download-extensions-exclude=asx,xml,pdf,xls,xlsx,doc,docx,ppt,pptx

Page 17: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

こんな感じ

• .archive はログ取り込み完了

– メモリ不足時などクラッシュ時、 .archive ファイルを消せば再取り込み

-rw-r--r--. 1 td-agent td-agent 843255 10月 17 21:10 2014 access.20141017T20_1.log.gz -rw-r--r--. 1 td-agent td-agent 2351 10月 17 22:15 2014 access.20141017T21_0.log.archive -rw-r--r--. 1 td-agent td-agent 899813 10月 17 21:35 2014 access.20141017T21_0.log.gz -rw-r--r--. 1 td-agent td-agent 2350 10月 17 22:16 2014 access.20141017T21_1.log.archive -rw-r--r--. 1 td-agent td-agent 743095 10月 17 22:10 2014 access.20141017T21_1.log.gz -rw-r--r--. 1 td-agent td-agent 2351 10月 17 23:15 2014 access.20141017T22_0.log.archive -rw-r--r--. 1 td-agent td-agent 893614 10月 17 22:34 2014 access.20141017T22_0.log.gz -rw-r--r--. 1 td-agent td-agent 2351 10月 17 23:16 2014 access.20141017T22_1.log.archive -rw-r--r--. 1 td-agent td-agent 589472 10月 17 23:10 2014 access.20141017T22_1.log.gz -rw-r--r--. 1 td-agent td-agent 2351 10月 18 00:15 2014 access.20141017T23_0.log.archive -rw-r--r--. 1 td-agent td-agent 901334 10月 17 23:39 2014 access.20141017T23_0.log.gz -rw-r--r--. 1 td-agent td-agent 2350 10月 18 00:16 2014 access.20141017T23_1.log.archive -rw-r--r--. 1 td-agent td-agent 397218 10月 18 00:10 2014 access.20141017T23_1.log.gz -rw-r--r--. 1 td-agent td-agent 7357230 10月 18 00:22 2014 access.20141018T00.b5059f9f70f1f05f5

Page 18: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

Piwik にも問題あるんじゃない(1)?

• MySQL の my.cnf で問題発覚

• 何をするオプションか: 「自動変換」をお断り

– カラムに入らなければ異常終了、受け付けない

• デフォルトでは「自動変換」、エラーにしない

– 65535 以上を 65534 にする int(11)

– 256 文字以上を切り捨て varchar(255)

– SJIS, EUC は適当に丸めて UTF8 カラムに入れる

[mysql] sql_mode = "TRADITIONAL"

Page 19: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

Piwik にも問題あるんじゃない(2)?

• 検索エンジンから文字コードが SJIS あるいは EUC である場合、文字化け

– 貴重な Yahoo、SJIS アクセス未だ多し。稀に EUC !

– ただし、検索エンジンについては、 piwik/core/DataFiles/SearchEngines.php で文字コードの指定が可能。されてないけどね。

• 自サイトの検索キーワードが...

– 文字コードの指定はできない。そういう発想なし。

• マルチバイトでもキーワードの 256 バイト以上が切り捨てられる。バイトです、えぇ

Page 20: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

直してしまおう

• piwik/core/DataFiles/SearchEngines.php

– 検索エンジンは片っ端から文字コードの指定

– 指定なしは新たに加えるデフォルト文字コード

• デフォルト指定で日本語文字コード以外でも OK

• 自サイトの検索キーワードについては...

– 検索エンジンのデフォルト指定に従う

• substr から mb_substr に変更します

– MySQL の varchar(255) に合わせたんだろうけど、varchar は文字数です。バイト数ではない。

Page 21: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

• Piwik メモリーを 2G 位に、デフォルトは 780 – 月半ばで archive 実行時メモリーが足らなくなる

– piwik/config/config.ini.php の General セクション

• Cron のタイミング – 一時間に一回程度かな

– 月末につれ archive が遅くなる • 月初の 5 倍程度。次の cron と当たらないようにする

[General] ; Minimum memory limit enforced when archived via ./console core:archive minimum_memory_limit_when_archiving = 2048

注意点

Page 22: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

• 100 万ページビュー /月(bot 込) いけます – ただし MySQL だけは割とサーバースペック高いです

• Urchin との比較 – Log (bot 込)はほぼ 100% 一致

– Tracker は 96 ~ 97% くらい

結果

A サイト bot 込ログ集計 10月10日(金) 10月11日(土) 10月12日(日)

Urchin (UTM なし) 171,302 173,624 114,291

Piwik 179,122 173,442 114,015

差(Piwik/Urchin) 99.90% 99.76% 99.80%

A サイト集計 10月10日(金) 10月11日(土) 10月12日(日)

Urchin (UTM) 51,252 20,921 19,561

Piwik (Tracker) 49,109 20,476 19,068

差(Piwik/Urchin) 95.82% 97.87% 97.48%

*UTM = Urchin Tracker Module

Page 23: Piwik fluentd

Piwik is the leading open source web analytics software, used by more than 460,000 websites. It gives interesting reports on your website visitors, your popular pages, the search engines keywords they used, the language they speak… and so much more. Piwik aims to be an open source alternative to Google Analytics. (JP)

Спасибо за внимание.

ご清聴ありがとうございました