awstatで携帯電話の機種を判別するメモ

awstatというと様々なログを解析して、その結果を表示してくれるソフト。

awstat6.5からはwwwroot/cgi-bin/lib/browsers_phone.pmというファイルに携帯電話の機種情報が入ってるんだが、なにぶん海外のソフトなので、日本の携帯電話のことは考えられていない。

完全日本語化のAWStatsもあるんだが、さすがにまだ携帯機種のほうには対応してないようだ→http://www.bflets.dyndns.org/Tools/AWStatsJpn.html

というわけで、携帯電話の機種を、browers_phone.pmに追加する方法をちょっくらメモ。ちなみに、最新版のawstat6.7(rpm版)でやりました。

まずは、設定ファイルをいじくる。

# vi /etc/awstats/awstats.example.com.conf
#-----------------------------------------------------------------------------
# OPTIONAL ACCURACY SETUP SECTION (Not required but increase AWStats features)
#-----------------------------------------------------------------------------

# The following values allow you to define accuracy of AWStats entities
# (robots, browsers, os, referers, file types) detection.
# It might be a good idea for large web sites or ISP that provides AWStats to
# high number of customers, to set this parameter to 1 (or 0), instead of 2.
# Possible values:
#    0      = No detection,
#    1      = Medium/Standard detection
#    2      = Full detection
# Change : Effective for new updates only
# Note   : LevelForBrowsersDetection can also accept value "allphones". This
#          enable detailed detection of phone/pda browsers.
# Default: 2 (0 for LevelForWormsDetection)
#
LevelForBrowsersDetection=allphones # 0 disables Browsers detection.
                                    # 2 reduces AWStats speed by 2%
                                    # allphones reduces AWStats speed by 5%

「LevelForBrowsersDetection=allphones」とする。

次は、問題のwwwroot/cgi-bin/lib/browsers_phone.pm。

# BrowsersSearchIDOrder
# This list is used to know in which order to search Browsers IDs (Most
# frequent one are first in this list to increase detect speed).
# It contains all matching criteria to search for in log fields.
# Note: Regex IDs are in lower case and ' ' and '+' are changed into '_'
#-------------------------------------------------------
@BrowsersSearchIDOrder = (
...
...いろいろと記述されてるが省略...
...
'n902i', # n902iを抽出してみる
);

IDは小文字でないとダメ(と書いてある)。こっちに追加したら、下のほうのこいつも忘れずに更新。

# BrowsersHashIDLib
# List of browser's name ('browser id in lower case', 'browser text')
#---------------------------------------------------------------
%BrowsersHashIDLib = (
...
...いろいろと記述されてるが省略...
...
'n902i','N902i (phone)',
);

「=>」をカンマで表現してるから、やや見にくい。

最後にawstats.plで更新するのを忘れずに。

# wwwroot/cgi-bin/awstats.pl -update -config=example.com

と、このように、@BrowsersSearchIDOrderにIDを追加して、%BrowsersHashIDLibにも、同じIDで表示用の名前を記述すれば、携帯機種別にアクセス件数を表示することが出来るようになった。下の画像ではちょっと機種が違うけど、こんなイメージ。

@BrowsersSearchIDOrderと%BrowsersHashIDLibの対応がおかしいと、

# wwwroot/cgi-bin/awstats.pl -update -config=example.com
Error: Not same number of records of BrowsersSearchIDOrder (??? entries) and BrowsersHashIDLib (??? entries without msie,netscape,firefox,svn) in Browsers database. May be you updated AWStats without updating browsers.pm file or you made changed into browsers.pm not correctly. Check your file  is up to date.
Setup ('/etc/awstats/awstats.example.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).

こんな風にエラーがでるので気をつけるべし。

OSの表示が不明のままなのがちょいと不満だが、こちらはwwwroot/cgi-bin/lib/operating_systems.pmに似たような感じで登録すれば表示される。この時、表示用アイコン(png)が必要っぽいので少し面倒。

携帯電話の機種にもアイコンを割り振れるのかな? それに関しては、実用上は問題なさそうなので調べてません。