… Apacheログ解析 Analog と ReportMagic

neko1sa.gif Apacheログ解析

Redhat系Linuxには、解析ツールのWebalizerというツールがデフォルトでありますけれど、ここでは AnalogとReportMagic をちょっとだけ試してみました。

analog_report01.png

Analog + ReportMagic

1.analog の導入


1.1 analog-6.0-1.src.rpm の入手
以下 URL よりパッケージを入手します。
http://www.analog.cx/

an01.png


1.2 source rpm のビルド

# rpm -ivh analog-6.0-1.src.rpm
# cd /usr/src/redhat/SPECS


1.3 SPEC ファイルの編集
SPEC ファイルの記述方法が古くなっているため、以下を編集する必要がありました。


-----
Name: analog
Version: 6.0
Release: 1
License: GPL   ← この行を追加
#Serial: 10   ← コメントアウト
Source: http://www.analog.cx/%{name}-%{version}.tar.gz
#Copyright: distributable   ← コメントアウト
Group: Utilities
URL: http://www.analog.cx/
BuildRoot: %{_tmppath}/anlg-root
-----

an02.png

1.4 ビルド
以下のコマンドにてパッケージをビルドします。

# rpmbuild -bb analog.spec


1.5 パッケージのインストール
以下のコマンドにてパッケージをインストールします。

# cd ../RPMS/i386
# rpm -ivh analog-6.0-1.i386.rpm


1.6 テスト
以下のコマンドにてテストを実施してみます。

# analog /var/log/httpd/access_log >index.html

カレントディレクトリに index.html ができていればテストは完了です。



2.ReportMagic の導入


2.1 rmagic-2.21.tar.gz の入手
以下 URL よりパッケージを入手します。
http://www.reportmagic.org/download.html

2.2 rmagic のビルド
以下のコマンドにてパッケージをビルドします。

# tar zxvf rmagic-2.21.tar.gz
# cd rmagic-2.21
# perl Install.PL

ここで対話的にインストールが進行するので、「自分で設定するか?」と尋ねられたとき no で答えると autoconfig モードとなります。
インストーラは自動的に CPAN に接続し、必要な perl モジュールをダウンロードをします。


2.3 テスト
以下のコマンドにてテストを実施してみます。

# ./rmagic.pl

./ は省略せず、必ずいれてください。
上記コマンドによって reports ディレクトリが作成され、html ファイルが出力されていれば基本的に導入は完了とします。



3. analog および ReportMagic の連携

analog はデフォルトで html 形式の出力を行い、設定によって直接 ReportMagic が処理できる COMPUTER 形式のデータファイルを出力することができます。

3.1 analog 側設定
analog 側で出力ファイル形式を切り替えるために /etc/analog.cfg に以下の設定を行います。

/etc/analog.cfg
-----
# Configuration file for analog 6.0
# See http://www.analog.cx/
#
# Here are a couple of configuration commands to get you started. Add any more
# you like from the Readme.
#
# Lines starting with # are comments.
#
# There is a much more extensive configuration file in examples/big.cfg
#
# If you need a LOGFORMAT command (most people don't -- try it without first!),
# it must go here, above the LOGFILE commands.
#LOGFILE logfile.log
LOGFILE /home/hoge/data/apache_log/access.log   ← 指定するログファイル
# LOGFILE /old/logs/access_log.*
OUTPUT COMPUTER   ← この行を追加
# OUTFILE Report.html   ← デフォルトをコメントアウト
OUTFILE /var/www/analog/Report.dat   ← 出力ファイルとして .dat 形式を追加
LANGUAGE JAPANESE   ← 日本語出力を指定
# HOSTNAME "[my organisation]"
#
-----


こののち以下のコマンドにて指定した形式のファイルが指定したパスに作成されることを確認します。
# analog


3.2 ReportMagic 側設定
ReportMagic 側設定はビルドディレクトリ中の rmagic.ini にて行います。
sample.ini を rmagic.ini へ mv し、[statistics] 項を以下のように編集します。

[statistics]
File_In = /var/www/analog/Report.dat   ← analog から渡されるデータファイル
Frame_File_Out = /var/www/analog/reports/index.html   ← 出力する index.html
Frame_Border = 0
No_Robots = 1
Log_File = rmagic.log    ← ReportMagic 動作ログ
Always_Quit = 1
#Language = ja   ← 日本語対応はできませんでした(エラーとなる)
#Include = standard.ini
Verbose = NWE
Format = XHTML 1.0



3.3 解析データの作成
上記の設定が完了したらビルドディレクトリ中にある rmagic.pl を以下の形式で実行し、ログファイルを確認します。


# ./rmagic.pl
# cat rmagic.log

rmagic.log
-----
Report Magic 2.21
Copyright (C) 1999-2003 Wadsack-Allen. All rights reserved.
rmagic: Beginning report creation (Sat Apr 4 21:53:53 2009).
rmagic: --> Settings file: ./rmagic.ini.
rmagic: --> Input data file: /var/www/analog/Report.dat.
rmagic: --> Output path: reports/.
rmagic: --> Output frameset file: reports/index.html.
rmagic: --> Output navigation file: reports/navfile.html.
rmagic: Creating report file in reports/GENERAL.html.
rmagic: WARNING: Can't open the Company_Logo file: fineprint.txt. Defaulting to standard logos.
rmagic: Creating report file in reports/MONTHLY.html.
rmagic: ... Creating graph file in reports/MONTHLY_line.png.
rmagic: Creating report file in reports/DAILYSUM.html.
rmagic: ... Creating graph file in reports/DAILYSUM_bar.png.
rmagic: Creating report file in reports/HOURLYSUM.html.
rmagic: ... Creating graph file in reports/HOURLYSUM_bar.png.
rmagic: Creating report file in reports/DOMAIN.html.
rmagic: Creating report file in reports/ORGANISATION.html.
rmagic: Creating report file in reports/SEARCHWORD.html.
rmagic: Creating report file in reports/OSREP.html.
rmagic: Creating report file in reports/STATUS.html.
rmagic: Creating report file in reports/SIZE.html.
rmagic: ... Creating graph file in reports/SIZE_bar.png.
rmagic: Creating report file in reports/FILETYPE.html.
rmagic: ... Creating graph file in reports/FILETYPE_bar.png.
rmagic: Creating report file in reports/DIRECTORY.html.
rmagic: ... Creating graph file in reports/DIRECTORY_bar.png.
rmagic: Creating report file in reports/REQUEST.html.
rmagic: Creating report file in reports/QUICK.html.
rmagic: Report creation complete (Sat Apr 4 21:54:06 2009).
-----



4. apache 側設定


WEB ブラウザから analog のマニュアルおよび解析データを閲覧できるよう、apache 側で以下の設定を行います。
ここで analog のドキュメントは http://localhost/analog_docs/ にて読めるようにし、また解析データは http://localhost/analog_data/ にてアクセスできるようにしました。


# -----------------------
# Alias for analog_docs:
# -----------------------

Alias /analog_docs "/var/www/docs"

<Directory "/var/www/docs">
#Options Indexes MultiViews
AllowOverride None
Order deny,allow
Deny from all
Allow from 192.168.0. 127.0.0.1
</Directory>

# -----------------------
# Alias for analog_data:
# -----------------------

Alias /analog_data "/var/www/analog"

<Directory "/var/www/analog">
#Options Indexes MultiViews
AllowOverride None
Order deny,allow
Deny from all
Allow from 192.168.0. 127.0.0.1
</Directory>


また、ReportMagic ドキュメントは /var/www/docs/rmagic に配置し、解析データは /var/www/analog/reports に配置しました。
このため、ReportMagic のドキュメントは http://localhost/analog_docs/rmagic/ にてアクセスし、また解析データは http://localhost/analog_data/reports/ にてアクセスします。
この http:// 以下の環境は適確、それぞれの環境に置き換えてくださいますよう。