|目次|手順 0|1|2|3|A|B|C|D|E|F|G|H| I |J|K|L|M|N|O|P|Q|
作成日:2001年03月08日、更新日:2004年03月23日 作成:鷹の巣AN HTTPDのクライアント機用アクセス解析ソフトとして、AWstatsを使用した設定例を説明します。
目次
鷹の巣が作成したHTMLファイルの作成用バッチファイル(makeuphtml.bat)の編集を行います。
各フォルダの配置が本例のとおりであれば、www.example.com以外は、何も変更する必要はありません。
D:\www\edit\awstats\wwwroot\cgi-bin\makeuphtml.batを開けて以下の三箇所だけを編集して下さい。
このバッチファイルを2003年1月として実行しますと、作成されるHTMLファイルのファイル名は、AWS200301.htmlとなるようにしています。作成されるHTMLファイル名を変更する場合は、このバッチファイル内で変更して下さい。
以下にHTML作成用バッチファイルの内容を示します。このバッチファイルは、18行目にカレントディレクトリを移動するコマンドを書いていますので、別にD:\www\edit\awstats\wwwroot\cgi-binのフォルダに置く必要はありません。コマンドプロンプト画面(DOS窓)を起動して最初に入力プロンプトが表示されるフォルダに設置して実行することもできます。
HTMLファイルの作成用バッチファイル(makeuphtml.bat)の内容
@echo off
rem ---------------------------------------------------------------------------------
rem AN HTTPD専用AWstats用HTMLファイル作成バッチファイル
rem URL:http://sakaguch.com 電子メール:http://sakaguch.com/cgi/postmail/ より送信して下さい。
rem ファイル名:makeuphtml.bat 2003.03.08 作成:鷹の巣 http://sakaguch.com/
rem 解説URL:http://sakaguch.com/SetAWstatsAnhttpd.html
rem 参考URL:AWStats Ver.5.0完全日本語版のページ
rem http://www.bflets.dyndns.org/Tools/AWStatsJpn.html
rem ---------------------------------------------------------------------------------
rem 改版記録:
rem 2003.03.08 Rev.1.000 初版で公開。
rem ---------------------------------------------------------------------------------
rem コマンドライン第1引数の%1には、西暦年データ4桁が設定されます。例.2003
rem コマンドライン第2引数の%2には、月 のデータ2桁が設定されます。例.01
echo makeuphtml.bat Rev.1.000(作成:鷹の巣)
if %2.==. goto ERROR
cd \www\edit\awstats\wwwroot\cgi-bin <--- awstats.plのあるフォルダ(ディレクトリ)に移動しますので、
このバッチファイルは、デスクトップやどこのフォルダ(ディレクトリ)にでも置けます。
rem 環境変数に設定
set AWstatsLogDir=D:\www\log <--- AN HTTPDのログファイルのあるフォルダ(ディレクトリ)を設定します。
set AWstatsOutDir=D:\www\edit\awstats\wwwroot\log <--- HTMLファイルを出力するフォルダ(ディレクトリ)を設定します。
set AWstatsHostName=www.example.com <--- 自ドメイン名を設定します。設定ファイルの、awstats.www.example.com.confに対応します。
echo ******** %1年%2月のログをファイルの前処理中です。 ********
echo ******** 処理結果は、combined.%1%2.logに出力されます。********
perl combined.pl -year=%1 -month=%2 -logdir=%AWstatsLogDir% -outdir=%AWstatsOutDir% -conv_ipaddr =y -conv_combine=y
echo ******** %1年%2月のログファイルの更新処理を行います。 ********
perl awstats.pl -config=%AWstatsHostName% -logfile=%AWstatsOutDir%\combined.%1%2.log -update
echo ******** %1年%2月のHTMLフォルダを検査しています。 ********
if not exist %AWstatsOutDir%\%1 mkdir %AWstatsOutDir%\%1
echo ******** %1年%2月のHTMLファイルを作成しています。 ********
perl awstats_buildstaticpages.pl -config=%AWstatsHostName% -lang=jp -dir=%AWstatsOutDir%\%1 -year=%1 -month=%2
echo ******** %1年%2月のHTMLファイル名を変更しています。 ********
perl linkreplace.pl -host=%AWstatsHostName% -htmldir=%AWstatsOutDir%\%1 -newfilename=AWS%1%2.html <--- 出力ファイル例.AWS200301.html
rem echo ******** %AWstatsOutDir%\combined.%1%2.logを消去しました。********
rem del %AWstatsOutDir%\combined.%1%2.log
rem 環境変数の消去
set AWstatsLogDir=
set AWstatsOutDir=
set AWstatsHostName=
goto END
:ERROR
echo 引数がありません。2003年01月のログを処理する場合は、
echo %0 2003 01 と入力して下さい。
:END
echo.
echo 終了します。何かキーを押してください . . .
pause >> NULL
アクセスログファイルがIPアドレスではなく、ホスト名で記録されている場合は、
perl combined.pl -year=%1 -month=%2 -logdir=%AWstatsLogDir% -outdir=%AWstatsOutDir% -conv_ipaddr =n -conv_combine=y
としますと、処理速度が著しく速くなります。
RefererとUser Agentのログファィルデータを利用しない場合は、
perl combined.pl -year=%1 -month=%2 -logdir=%AWstatsLogDir% -outdir=%AWstatsOutDir% -conv_ipaddr=y -conv_combine=n
として下さい。
HTMLファイルの作成用バッチファイル(makeuphtml.bat)のアイコンリンク(ショートカット)をデスクトップなどに設置します。アイコンリンク(ショートカット)のプロパティタブに引数を書き込んで、そのアイコンをクリックし、HTMLファイルを作成することもできます。
通常は、以下の実行画面例のように、コマンドプロンプト画面(DOS窓)を起動して、makeuphtml.batのあるD:\www\edit\awstats\wwwroot\cgi-binのフォルダに移動し、バッチファイルを実行します。makeuphtml.batは、引数として処理年データと処理月データを与えて起動します。
この例では、2003年2月のHTMLファイルの作成を行なって、D:/www/edit/awstats/wwwroot/log/2003のフォルダにHTMLファイルを作成しています。2003年2月のデータ作成にノートパソコン(Windows XP HOME EDITION、CPU:celeron800MHz、メモリ256MB)を使用して、約4時間30分を要しました。その内の4時間は、アクセスログファイルのIPアドレスをホスト名に変換する処理時間でした。
画面の文字色は、先頭の3行の水色がキーボード入力を表わし、赤色が私が書き込んだ説明を表わしています。先頭の3行以外の水色は、画面に表示されませんが説明のために私がキーボード入力として挿入しました。各コマンドを単独に実行する場合の参考として下さい。黄色は、処理毎やフォルダ環境によって変わる内容を表わしています。緑色は、各コマンドを実行した結果の表示です。
HTMLファイルの作成用バッチファイル(makeuphtml.bat)の実行例(2003年2月のHTMLファイルを作成)
C:\Documents and Settings\user>D:\↓ D:\>cd \WWW\edit\awstats\wwwroot\cgi-bin↓ D:\www\edit\awstats\wwwroot\cgi-bin>makeuphtml.bat 2003 02↓ <--- このように処理年データと処理月データを引数として与えて起動します。 makeuphtml.bat Rev.1.000(作成:鷹の巣) ******** 2003年02月のログをファイルの前処理中です。 ******** ******** 処理結果は、combined.200302.logに出力されます。******** D:\www\edit\awstats\wwwroot\cgi-bin>perl combined.pl -year=2003 -month=02 -logdir=D:\www\log -outdir=D:\www\edit\awstats\wwwroot\log -conv_ipaddr =y -conv_combine=y <--- 注)1 combined.pl Rev.1.000(作成:鷹の巣) D:/www/log/httpd.20030201.logを処理中です。 5000 10000 15000 20000 25000 30000 35000 40000 45000 50000 52026 <--- あまりに処理時間が長いので、処理済み行数を5000行毎に表示します。 D:/www/log/httpd.20030201.log と D:/www/log/referer.20030201.log と D:/www/log/ua.20030201.log を合成して、D:/www/edit/awstats/wwwroot/log/combined.200302.logに出力中 ・・・中略・・・ D:/www/log/httpd.20030228.logを処理中です。 5000 10000 15000 20000 25000 30000 35000 35769 D:/www/log/httpd.20030228.log と D:/www/log/referer.20030228.log と D:/www/log/ua.20030228.log を合成して、D:/www/edit/awstats/wwwroot/log/combined.200302.logに出力中 処理が終了しました。 combined.pl Rev.1.000(作成:鷹の巣) ******** 2003年02月のログファイルの更新処理を行います。 ******** D:\www\edit\awstats\wwwroot\cgi-bin>perl awstats.pl -config=www.example.com -logfile=D:\www\edit\awstats\wwwroot\log\combined.200302.log -update <--- 注)2 Update for config "awstats.www.example.com.conf" With data in log file "D:\www\edit\awstats\wwwroot\log\combined.200302.log"... Phase 1 : First bypass old records, searching new record... Phase 2 : Now process new records (Flush history on disk after 16000 hosts)... Flush history file on disk (unique hosts reach flush limit of 16000) Flush history file on disk (unique hosts reach flush limit of 16000) Flush history file on disk (unique hosts reach flush limit of 16000) Flush history file on disk (unique hosts reach flush limit of 16000) Lines in file: 1259559 Found 7625 dropped records, Found 173 corrupted records, Found 1 old records, Found 1251760 new qualifed records. ******** 2003年02月のHTMLフォルダを検査しています。 ******** D:\www\edit\awstats\wwwroot\cgi-bin>if not exist D:\www\edit\awstats\wwwroot\log\2003 mkdir D:\www\edit\awstats\wwwroot\log\2003 <--- 注)3 ******** 2003年02月のHTMLファイルを作成しています。 ******** D:\www\edit\awstats\wwwroot\cgi-bin>perl awstats_buildstaticpages.pl -config=www.example.com -lang=jp -dir=D:\www\edit\awstats\wwwroot\log\2003 -year=2003 -month=02 <--- 注)4 Build main page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output Build alldomains page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=alldomains Build allhosts page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=allhosts Build lasthosts page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=lasthosts Build unknownip page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=unknownip Build alllogins page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=alllogins Build lastlogins page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=lastlogins Build allrobots page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=allrobots Build lastrobots page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=lastrobots Build urldetail page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=urldetail Build urlentry page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=urlentry Build urlexit page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=urlexit Build unknownos page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=unknownos Build unknownbrowser page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=unknownbrowser Build browserdetail page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=browserdetail Build refererse page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=refererse Build refererpages page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=refererpages Build keyphrases page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=keyphrases Build keywords page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=keywords Build errors404 page: "awstats.pl" -config=www.example.com -staticlinks -lang=jp -month=02 -year=2003 -output=errors404 20 files built. Main page is 'awstats.www.example.com.html' ******** 2003年02月のHTMLファイル名を変更しています。 ******** D:\www\edit\awstats\wwwroot\cgi-bin>perl linkreplace.pl -host=www.example.com -htmldir=D:\www\edit\awstats\wwwroot\log\2003 -newfilename=AWS200302.html <--- 注)5 linkreplace.pl Rev.1.000(作成:鷹の巣) D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.alldomains.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302alldomains.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.allhosts.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302allhosts.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.alllogins.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302alllogins.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.allrobots.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302allrobots.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.browserdetail.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302browserdetail.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.errors404.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302errors404.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.keyphrases.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302keyphrases.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.keywords.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302keywords.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.lasthosts.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302lasthosts.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.lastlogins.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302lastlogins.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.lastrobots.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302lastrobots.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.monthdayvalues.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302monthdayvalues.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.refererpages.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302refererpages.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.refererse.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302refererse.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.unknownbrowser.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302unknownbrowser.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.unknownip.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302unknownip.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.unknownos.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302unknownos.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.urldetail.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302urldetail.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.urlentry.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302urlentry.html D:/www/edit/awstats/wwwroot/log/2003/awstats.www.example.com.urlexit.html---> D:/www/edit/awstats/wwwroot/log/2003/AWS200302urlexit.html 処理が終了しました。 linkreplace.pl Rev.1.000(作成:鷹の巣) 終了します。何かキーを押してください . . . ↓ D:\www\edit\awstats\wwwroot\cgi-bin>
combined.plの処理は、httpd.20030201.logから、httpd.20030228.logまでのログファイルを連結し、1ヶ月分の1つのファイルcombined.200302.logにします。この間、IPアドレスをホスト名に変換したり、RefererとUser Agentのログファィルデータの連結も行います。作成される1ヶ月分の1つのファイルの漢字コードは、UTF-8コードに変換されています。
awstats.pl -updateで行なう処理は、combined.200302.logから統計データの作成を行います。この統計データは、
D:\www\edit\awstats\wwwroot\cgi-binのフォルダのawstats022003.www.example.com.txtというファイル名です。このデータがあれば、いつでもHTMLファイルが生成出来ますので、必ずバックアップをとっておきましょう。(過去にこのデータの記録様式が変わりましたが、様式変換スクリプトが準備されました。将来のためにもバックアップをとっておかれることを推奨します。)
1ヶ月あたりの生成されるHTMLファイルは、20個です。一年単位では、240個になりますので、年度別にフォルダ(ディレクトリ)を作成することにしました。ここでは、ログファイルのフォルダ(D:/www/edit/awstats/wwwroot/log)の下に2003というフォルダを作成しています。
awstats_buildstaticpages.plの処理は、awstats022003.www.example.com.txtというファイルから、HTMLファイルを作成します。作成されたHTMLのファイル名は、awstats.www.example.com.alldomains.htmlのような非常に長い名前になります。localeファイルはUTF-8コードのままですから、このHTMLファイルは、UTF-8コードで記述されています。
linkreplace.plの処理は、この長いHTMLのファイル名をAWS200302alldomains.htmlのような普通のファイル名に変更します。ただし、awstats.www.example.com.html内には、各HTMLファイルへのアンカー(ハイパーリンク)が存在しますので、このアンカー先の書き換えも行います。
perl awstats.pl -config=www.example.com -output -staticlinks -year=2003 -month=02 > AWS200302.html
perl awstats_buildstaticpages.pl -config=www.example.com -lang=jp -year=2003 -month=02 > AWS200302.html
としてもアンカー(ハイパーリンク)先がawstats.www.example.com.XXXX.htmlのようになっていましたので、ただそれだけのために作ったperlスクリプトです。Windows 2000では、バッチファイル内に以下のshellコマンドを複数のファイルに実施するように書いた場合と同じです。
D:\>if exist AWS200302.html del AWS200302.html↓ <--- リネーム先ファイルがあれば、消去する。 D:\>rename awststs.www.example.com.html AWS200302.html↓ <--- 短いファイル名に変更する。 D:\>perl -p -i.orig -e "s/awstats.www.example.com.(.*)html/AWS200302$1html/g" AWS200302.html↓ <--- AWS200302.html内の文字列の置換 注) D:\>del AWS200302.html.orig↓ <--- バックアップファイルの削除
AN HTTPDのログファイルの更新が毎日ではない場合
ログファイル(combined log format)から、1ヶ月分のデータを取り出し、ファイル名を変更します。例えば、2003年2月のデータでしたら、ファイル名をhttpd.20030201.log(2003年2月1日分のデータの中に1ヶ月分のデータを入れたもの)とします。
同様にreferer.20030201.logやua.20030201.logも作成して下さい。ログファイル名は、必ず毎日更新のような形式になっている必要があります。
Apacheのログファイルに対応させる方法
このようにログファィル名をだますと、使用することができます。
IISのログファイルに対応させる方法
AN HTTPDのログファィルより生成されたcombined.yyyymm.logについて
2003年1月のアクセス解析(RefererとUser Agentのデータなし)と2003年2月のアクセス解析(RefererとUser Agentのデータあり)を比較して頂くとお解りになると思いますが、AWstatsのログ解析での差異は、以下のようになっています。
このcombined.yyyymm.logをAWstats以外のログ解析に使用した場合は、変な解析データが出力される可能性があります。HTMLファイルが出来上がりましたら、このいい加減なcombined.yyyymm.logは、早速削除されることをお薦めします。
AN HTTPDのRefererファイルを早急に解析される方のために
AWstatsのログの解析結果は、多種にわたり、素晴らしいものです。ただ、いくら無人でHTMLファイルが生成できるといっても処理時間が長時間におよぶことが唯一の欠点とも言えます。(IPアドレスの逆引きでホスト名に変換しない場合を除く)
Refererファイルだけの解析でしたら、是非、私の作成した「AN HTTPD用refererファイル解析Perlスクリプト(jcode.pmやEncodeモジュール使用)」を試して下さい。下記の様な内容が比較的短時間で、わかります。
ただし、Windows用のActive Perl 5.6.1.633 built for MSWin32-x86-multi-threadに「Windows用Jcode.pmのインストール方法」で、jcode.pm ver.0.82をインストールする必要があります。尚、Active Perl 5.8では、このモジュールに替わるEncodeモジュールが標準で組み込まれましたので、このバージョン以降は、jcode.pmをインストールする必要は、ありません。ただし、現状のバージョンでは、読み込むデータの文字コードの自動認識に失敗し、生成されるデータ数が若干少なくなります。興味のある方は、このスクリプトでEncodeモジュールを使用した内容をご覧になって下さい。
作成されたHTMLファイルは、全てUTF-8コードです。現在、ブラウザのIE6などで問題なく閲覧することができます。他のブラウザを使用した場合にUTF-8コードで文字化けする心配がある方は、シフトJIS(SJIS)に変換して下さい。 色々なツールがありますが、複数のHTML&テキストファイル内を一括置換TextSS Ver.3.12というフリーソフトを使用すれば、指定フォルダ以下のファイルが一括してコード変換できます。
ただし、メタタグの
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=euc-jp">を
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=Shift_JIS">に
変更することをお忘れなく。
本サイトの設定例は、最初の第1歩だと考えて下さい。自サイトの状況に合わせた詳細な設定方法は、前編の冒頭に示しましたログ解析スクリプトAWStatsドキュメントをご参照願います。