cronの設定とアクセス解析-2

visitorsで解析

ログファイルが正常に作成されているのを確認した
毎日の解析は上書き、先月のログ解析を蓄積
ログファイルが増えると、ファイル名の間違いで止まるので要注意

visitors
通常モード
visitors -A -m 30 -o html /var/log/apache2/access_log.1 > /home/httpd/report.html

画像作成
visitors /var/log/apache2/access_log.1 –prefix http://a-po.info -V > /home/httpd/report.dot
dot -Tpng /home/httpd/report.dot > /home/httpd/report.png

ファイル名に日付付加
visitors -A -m 30 -o html /var/log/apache2/access_log.1 > /home/httpd/`date –date +%Y%m`report.html

visitorsは通常のHTML出力と画像によるフローチャートの出力がある。
画像の作成は、dotファイル作成後にpngへ変換している。

access_log
001access_log

access_log と 001access_log     (直近ログ)
access_log.1 と 001access_log.1   (先月ログ)


#!/bin/bash

visitors -GKZRXYS -m 20 /var/log/apache2/access_log –trails –prefix http://www.example.com -o html > /home/httpd/html/visitors/report.html
visitors /var/log/apache2/access_log –prefix http://www.example.com -V > /home/httpd/html/visitors/graph.dot
dot -Tpng /home/httpd/html/visitors/graph.dot > /home/httpd/html/visitors/graph.png

visitors -GKZRXYS -m 20 /var/log/apache2/001access_log –trails –prefix http://001.example.com -o html > /home/httpd/html/visitors/report2.html
visitors /var/log/apache2/001access_log –prefix http://001.example.com -V > /home/httpd/html/visitors/graph2.dot
dot -Tpng /home/httpd/html/visitors/graph2.dot > /home/httpd/html/visitors/graph2.png

cron.dailyへ放り込む
2つのバーチャルホストのアクセス解析が毎日出来上がる。

report.html    http://www.example.com
graph.png     http://www.example.com
report2.html   http://001.example.com
graph2.png    http://001.example.com



毎月CRON(先月のデータ集計月別保存)

#!/bin/bash

visitors -GKUZWMRDOBXYS -m 20 /var/log/apache2/access_log.1 –trails –prefix http://www.example.com -o html > /home/httpd/html/visitors/`date –date ‘1 month ago’ +%Y%m`_www.html
visitors /var/log/apache2/access_log.1 –prefix http://www.example.com -V > /home/httpd/html/visitors/`date –date ‘1 month ago’ +%Y%m`.dot
dot -Tpng /home/httpd/html/visitors/`date –date ‘1 month ago’ +%Y%m`.dot > /home/httpd/html/visitors/`date –date ‘1 month ago’ +%Y%m`.png

visitors -GKUZWMRDOBXYS -m 20 /var/log/apache2/access-blog_log.1 –trails –prefix http://001.example.com -o html > /home/httpd/html/visitors/`date –date ‘1 month ago’ +%Y%m`_001.html
visitors /var/log/apache2/access-blog_log.1 –prefix http://001.example.com -V > /home/httpd/html/visitors/`date –date ‘1 month ago’ +%Y%m`_001.dot
dot -Tpng /home/httpd/html/visitors/`date –date ‘1 month ago’ +%Y%m`_blog.dot > /home/httpd/html/visitors/`date –date ‘1 month ago’ +%Y%m`_001.png

cron.monthlyへ放り込む

200907.html
200907.png
200907_001.html
200907_001.png

何かのトラブルがあったとしても、あとでpngの再度作成が不要であれば、dotファイルはバーチャルホストごとに固定したファイル名でも良い
visitors /var/log/apache2/access_log.1 –prefix http://www.example.com -V > /home/httpd/html/visitors/www.dot
dot -Tpng /home/httpd/html/visitors/www.dot > /home/httpd/html/visitors/`date –date ‘1 month ago’ +%Y%m`.png



オプション
-G GoogleとGoogle Adsensedのクローラアクセス記録。上位ページが最新アクセス
-K Google経由のアクセスで検索に使用されたキーワード。上位のキーワードほど検索回数が多い
-Z Google経由のアクセスで検索に使用されたキーワード。上位のキーワードほど最新のアクセスに使用
-H Google経由でのアクセスで、そのユーザの言語の種類
-U アクセスのあったUA表示(OS、ブラウザなど)
-W アクセス量を週(月曜日~日曜日)時間(0-23)で表示。明るい場所がアクセス多、暗い場所はアクセス少
-M アクセス量を月(1月から12月)と日毎表示。明るい場所がアクセス多、暗い場所はアクセス少
-R リファラー情報。上位の情報ほど最新アクセス情報
-D アクセス元のトップレベルのドメイン
-O アクセスしてきたOS
-B アクセスしてきたブラウザ
-X 存在しないファイルへのアクセスエラー
-Y 1訪問あたり(ユニークユーザ単位)のページビュー
-S 検索ロボットやスパイダーのアクセス
-A 「-GKUWRDOB」を指定と同じ
-m 各表示内容で表示する件数指定「-m 30」で各30件ずつ
-o 出力するファイル形式。指定できるのは2種類「html」「text」。「-o html」でhtml出力
-T サイト内のでのページ間移動の情報表示「-P サイトのURL」オプションと同時に使用

ストリームモードとやらもあるが、手をつけていない
update-every 300 出力タイミング
reset-every 3600 解析結果情報をリセット
tail -f /var/log/apache2/access_log.1 | /usr/bin/logresolve | visitors –stream -A –update-every 300 –reset-every 3600 –output-file /home/httpd/report-stream.html



ちょうど月が変わった本日、1日にcron.dailyが実行され、その後にcron.monthlyが実行される
cron.monthlyで、ローテされた先月のログが解析されるはずだったが、ログファイルが無いと怒られた。
※安定動作するまでメールが届けられるように設定している。
ちなみにcronの順序はアルファベット順なので、動作に問題があるときは順番を見直してみる。



出来上がった解析を見てみると、どうやらログファイルのファイル名の間違いクサイ
いま一度、ログファイルの中身と、cronに記述したファイル名を確認
問題点や改善点を検討したい