Webalizer

1. Webサーバ統計情報を htmlファイルで保存する


Webサーバの アクセスログ(access.log) ファイルから統計結果を作成し、HTML ファイルや PNG ファイル型式で保存する機能を備えるアプリケーション
HTML 形式なので、一般的な Web ブラウザで表示させる事が可能と なっている

Debian のバージョンは 7.0(Wheezy) 若(も)しくは 8.0(Jessie) を想定している
Jessie で あれば Webalizer のバージョンは 2.23.08 と なる



2. 設定ファイル類


Webalizer が参照する設定ファイルは、標準で以下に配置される
勿論、別のディレクトリを指定する事も可能

# ただし、変更する意義は余り無いと言うか、別ディレクトリを指定している場面を見た事は無い

/etc/webalizer/webalizer.conf
.html 等の統計結果の保存先は、標準で以下に配置される
これも、別のディレクトリを指定する事が可能
/var/www/webalizer
# こちらは、標準のディレクトリでは支障が生じる人も いるかも知れない



3. 導入


Debian パッケージが用意されているので、以下の様に簡単に導入する事が可能
apt-get install webalizer
apt-get install ttf-kochi-gothic
(若しくは apt-get install ttf-kochi-mincho)
日本語表示は不要という事で あれば、東風(こち) True Type Font は不要か
ゴシック(gothic)書体が選ばれる傾向が高い様で あるが、好みで明朝体を選んでも良い
単に htmlファイルが どう表示されるか だけ となる

なお、Jessie では True Type Font を導入せずとも日本語表示に支障は無い様(よう)に見えるが、気の せいか



4. 設定


.1 Webalizer 設定


導入後、公開している Webサーバの特性(アクセス数の多寡等)や統計結果の運用方針等に合わせて webalizer.conf を変更する
cd /etc/webalizer
cp -p webalizer.conf webalizer.conf.org
vi webalizer.conf
# LogFile defines the web server log file to use. If not specified
# here or on on the command line, input will default to STDIN. If
# the log filename ends in '.gz' (a gzip compressed file), or '.bz2'
# (bzip2 compressed file), it will be decompressed on the fly as it
# is being read.

LogFile /var/log/apache2/access.log.1
統計算出の対象と する accesslog ファイルの指定、と言う事か
以下の様に変更しておく
変更後設定
LogFile /var/log/apache2/access.log
# LogType defines the log type being processed. Normally, the Webalizer
# expects a CLF or Combined web server log as input. Using this option,
# you can process ftp logs (xferlog as produced by wu-ftp and others),
# Squid native logs or W3C extended format web logs. Values can be 'clf',
# 'ftp', 'squid' or 'w3c'. The default is 'clf'.

#LogType clf
統計算出の対象と するログファイルの型式指定、と言う事か
wu-ftp 等、今も使用している人が いるので あろうか
squid は現役で使用されていると思うが、統計対象は Apache のアクセスログなので、何も指定しない状態と して おく
何も指定していないと、標準の clf 型式が採用される
# OutputDir is where you want to put the output files. This should
# should be a full path name, however relative ones might work as well.
# If no output directory is specified, the current directory will be used.

OutputDir /var/www/webalizer
統計結果の格納先を記述する
これは標準ディレクトリから変更したい人も いるかも知れない
# HistoryName allows you to specify the name of the history file produced
# by the Webalizer. The history file keeps the data for previous months,
# and is used for generating the main HTML page (index.html). The default
# is a file named "webalizer.hist", stored in the output directory being
# used. The name can include a path, which will be relative to the output
# directory unless absolute (starts with a leading '/').

#HistoryName webalizer.hist
統計算出履歴ファイル、とでも言うべきか
ファイル名の指定で あるが、通常の運用では変更の必要性は低いか
# Incremental processing allows multiple partial log files to be used
# instead of one huge one. Useful for large sites that have to rotate
# their log files more than once a month. The Webalizer will save its
# internal state before exiting, and restore it the next time run, in
# order to continue processing where it left off. This mode also causes
# The Webalizer to scan for and ignore duplicate records (records already
# processed by a previous run). See the README file for additional
# information. The value may be 'yes' or 'no', with a default of 'no'.
# The file 'webalizer.current' is used to store the current state data,
# and is located in the output directory of the program (unless changed
# with the IncrementalName option below). Please read at least the section
# on Incremental processing in the README file before you enable this option.

#Incremental no
増分加算集計の手法指定、とでも表記すれば良いか
前回統計結果を保持した状態で追加統計の算出を行うか どうかの指定
機能が分かりにくく、把握しにくい
標準では機能無効

logrotate 等のアプリケーションで分断されているアクセスログに対して統計算出を行うと、前回統計分が初期化されてしまう
これだと月毎統計を行っても前回統計値が失われて無意味な統計結果と なってしまう

これを回避するため、前回統計結果を予め保持して おき、それに追加で統計値を合算させる事で月毎統計を算出させる事が可能と なる

1ヶ月よりも短い周期(通常は週毎が指定されている)でアクセスログをローテートしている環境では、有効化して おく
変更後設定
Incremental yes
# IncrementalName allows you to specify the filename for saving the
# incremental data in. It is similar to the HistoryName option where the
# name is relative to the specified output directory, unless an absolute
# filename is specified. The default is a file named "webalizer.current"
# kept in the normal output directory. If you don't specify "Incremental"
# as 'yes' then this option has no meaning.

#IncrementalName webalizer.current
増分加算集計の現状状態を保持しているファイル名を指定
ディレクトリは上記の
OutputDir /var/www/webalizer
が利用される

因(ちな)みに webalizer.current は通常のテキストファイルなので、cat 等で統計状態を閲覧出来る
実際には この様な内容と なっている
root:/var/www/webalizer# more webalizer.current
# Webalizer V2.23-05 Incremental Data - 06/02/2014 09:43:47
2014 6 2 9 43 47

- 省略 -

# -usernames-
# End Of Table - usernames
# ReportTitle is the text to display as the title. The hostname
# (unless blank) is appended to the end of this string (seperated with
# a space) to generate the final full title string.
# Default is (for english) "Usage Statistics for".

ReportTitle Usage statistics for
統計結果の最上部に表示される名称を指定
通常は変更不要
# HostName defines the hostname for the report. This is used in
# the title, and is prepended to the URL table items. This allows
# clicking on URLs in the report to go to the proper location in
# the event you are running the report on a 'virtual' web server,
# or for a server different than the one the report resides on.
# If not specified here, or on the command line, webalizer will
# try to get the hostname via a uname system call. If that fails,
# it will default to "localhost".

#HostName www.webalizer.org
統計結果のホスト名を指定と あるが、ホスト名では なく公開している Webサーバの FQDN 名を記述した方が良いか
# HTMLExtension allows you to specify the filename extension to use
# for generated HTML pages. Normally, this defaults to "html", but
# can be changed for sites who need it (like for PHP embeded pages).

#HTMLExtension html
統計結果ファイルの拡張子を指定、と言う事か
何も指定しなければ標準の拡張子 HTML が採用される
例として PHP 拡張子を挙げているが、その指定に変更する人が いるので あろうか
# PageType lets you tell the Webalizer what types of URLs you
# consider a 'page'. Most people consider html and cgi documents
# as pages, while not images and audio files. If no types are
# specified, defaults will be used ('htm*', 'cgi' and HTMLExtension
# if different for web logs, 'txt' for ftp logs).

PageType htm*
PageType cgi
#PageType phtml
PageType php3
#PageType pl
PageType php
PageType(拡張子) の対象指定と除外、と言う事か
公開 Webサーバ次第で、適宜指定
# UseHTTPS should be used if the analysis is being run on a
# secure server, and links to urls should use 'https://' instead
# of the default 'http://'. If you need this, set it to 'yes'.
# Default is 'no'. This only changes the behaviour of the 'Top
# URLs' table.

#UseHTTPS no
HTTPS 形態での統計選択の指定、と言う事か
何も指定しなければ標準の HTTPS 無効化状態が採用される
# DNSCache specifies the DNS cache filename to use for reverse DNS lookups.
# This file must be specified if you wish to perform name lookups on any IP
# addresses found in the log file. If an absolute path is not given as
# part of the filename (ie: starts with a leading '/'), then the name is
# relative to the default output directory. See the DNS.README file for
# additional information.

#DNSCache dns_cache.db
逆引き DNS 結果の保持用データベースファイル名の指定、のみ ならず DNS 逆引きの動作指定

標準状態では、逆引きは行わないがデータベース名は dns_cache.db、と なる
逆引きを行いたい場合は以下の様に有効化して おく
DNSCache dns_cache.db
データベースファイルのディレクトリは上記の
OutputDir /var/www/webalizer
が利用されるが、このデータベースファイルは絶対パス(path) 指定が可能で ある らしい
# DNSChildren allows you to specify how many "children" processes are
# run to perform DNS lookups to create or update the DNS cache file.
# If a number is specified, the DNS cache file will be created/updated
# each time the Webalizer is run, immediately prior to normal processing,
# by running the specified number of "children" processes to perform
# DNS lookups. If used, the DNS cache filename MUST be specified as
# well. The default value is zero (0), which disables DNS cache file
# creation/updates at run time. The number of children processes to
# run may be anywhere from 1 to 100, however a large number may effect
# normal system operations. Reasonable values should be between 5 and
# 20. See the DNS.README file for additional information.

#DNSChildren 0
逆引き DNS を行う際の子プロセス(processes) 数の指定、と言う事か
標準状態では、統計結果の IPアドレス 1つ毎に逆引きを実施する、と言う事に なる様で ある
アクセス数が多い公開 Webサーバでは、逆引きに時間を費やしてしまう事が考えられるため、サーバの CPU 等に負荷を掛けない程度に並行処理を行うプロセス数を指定して おく
# CacheIPs allows unresolved IP addresses to be cached in the DNS
# database. Normally, only resolved addresses are saved. At some
# sites, particularly those with a large number of unresolvable IP
# addresses visiting, it may be useful to enable this feature so
# those addresses are not constantly looked up each time the program
# is run. Values can be 'yes' or 'no', with 'no' being the default.

#CacheIPs no
DNS で逆引き応答が得られない IPアドレスの保持手法指定、と言う事か
この機能の有用性が良く分からない
通常は指定不要で あり、変更しない
# CacheTTL specifies the time to live (TTL) value for cached DNS
# entries, in days. This value may be anywhere between 1 and 100
# with the default being 7 days (1 week).

#CacheTTL 7
逆引き DNS データベースの保持期間を指定
変更しても一長一短あるので、変更しない方が無難
# HTMLHead defines HTML code to insert within the <HEAD></HEAD>
# block, immediately after the <TITLE> line. Maximum line length
# is 80 characters, so use multiple lines if needed.

#HTMLHead
#HTMLHead
HTML ヘッダに関する個別指定行が必要な場合に指定を追加
文字コードの指定位は あっても良いか
# IgnoreState also shouldn't be used, but is here anyway. It is
# similar to the IgnoreHist option, but for the incremental data
# file. If this is set to 'yes', any existing incrememtal data
# will be ignored and a new data file will be written at the end
# of processing. USE WITH CAUTION. By ignoring an existing
# incremental data file, all previous processing for the current
# month will be lost, and those logs must be re-processed.
# Valid values are "yes" or "no". Default is "no".

#IgnoreState no
現状統計結果の無視指定、とでも表記すれば良いか
機能が良く分からないので、標準の無効化から有効化(yes) に変更してみた所、上記で表れた以下の対象に対して、現状統計結果よりも前の統計結果を捨てると言う動作が行われた
LogFile /var/log/apache2/access.log
本機能の有用性が良く分からないが、そう言うものか
# Your own site should be hidden
#HideSite *webalizer.org
#HideSite localhost
機能が良く分からず、把握しにくい
統計結果からの表示除外を意図する対象接続元の意か?
# Your own site gives most referrals
#HideReferrer webalizer.org/
機能が良く分からず、把握しにくい
統計結果からの表示除外を意図する対象参照元(リンク移動元)の意か?
# Usually you want to hide these
HideURL *.gif
HideURL *.GIF
HideURL *.jpg
HideURL *.JPG
HideURL *.png
HideURL *.PNG
HideURL *.ra
統計結果からの表示除外を意図する対象公開ファイルの拡張子を指定
# Hiding agents is kind of futile
#HideAgent RealPlayer
統計結果からの表示除外を意図する対象エージェント(user agent)名称を指定
# The Ignore* keywords allow you to completely ignore log records based
# on hostname, URL, user agent, referrer or username. I hesitated in
# adding these, since the Webalizer was designed to generate _accurate_
# statistics about a web servers performance. By choosing to ignore
# records, the accuracy of reports become skewed, negating why I wrote
# this program in the first place. However, due to popular demand, here
# they are. Use the same as the Hide* keywords, where the value can have
# a leading or trailing wildcard '*'. Use at your own risk ;) Please
# remember, the use of these will MAKE YOUR STATS INACCURATE and you
# should consider using an equivalent 'Hide*' keyword instead.

#IgnoreSite bad.site.net
IgnoreSite localhost
#IgnoreURL /test*
#IgnoreReferrer file:/*
IgnoreReferrer localhost
#IgnoreAgent RealPlayer
#IgnoreUser root
統計算出から除外したい各種内容を指定
#TrueTypeFont
日本語フォントを指定
TrueTypeFont /usr/share/fonts/truetype/kochi/kochi-gothic.ttf

(明朝体書体を導入している場合は以下の様に指定

TrueTypeFont /usr/share/fonts/truetype/kochi/kochi-mincho.ttf)

通常の運用で あれば、見るべき箇所は この位で あろうか

上記にも書いて いるが、Jessie では True Type Font を指定せずとも正常に日本語部分を表示出来ている様に見える
Wheezy では この指定が無いと日本語部分が化けて表示出来なかった


.2 Apache 設定


Debian パッケージの Apache と Webalizer の組み合わせではエージェント(user agent)統計の表示に問題が ある らしい
どうやら Apache パッケージでは、標準ではエージェント名称が記録されない状態と なっている らしい

Apache の設定ファイル(/etc/apache2/apache2.conf) の変更が必要との事、だそうで ある
# 本当か?
cd /etc/apache2
cp -p apache2.conf apache2.conf.[日付適当に]
vi apache2.conf
変更前
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
変更後
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combined
ここで一旦 Apache を停止
/etc/init.d/apache2 stop
(service apache2 stop でも良い)
既存の access.log ファイルのローテート連番を増数して おく
伝わりにくいかも知れないが、例えば最も過去のアクセスログが access.log.50.gz で ある場合、以下の様に 1ずつ番号を繰り上げると言う事で ある
cd /var/log/apache2
mv access.log.50.gz access.log.51.gz
mv access.log.49.gz access.log.50.gz

- 省略 -

mv access.log.2.gz access.log.3.gz
gzip access.log.1
mv access.log.1.gz access.log.2.gz
mv access.log access.log.1
ファイル数が多い場合、手作業対応では誤作業も発生し易いので、簡易にシェルスクリプトを書いて対応した方が無難か

ここで Apache を起動
/etc/init.d/apache2 start
(service apache2 start でも良い)



5. 運用


.1 既存アクセスログの統計算出


既存の access.log.* を手作業で統計算出する

最も過去のアクセスログが access.log.50.gz で ある場合、以下の様に実行
webalizer /var/log/apache2/access.log.51.gz
webalizer /var/log/apache2/access.log.50.gz

- 省略 -

webalizer /var/log/apache2/access.log.2.gz
webalizer /var/log/apache2/access.log.1
まとめて一度に実行しても概(おおむ)ね問題無いと思うが、場合に よっては不整合レコードが発生する可能性も あるので、一行毎に実行し他方が確実か
次に、現在使用中の access.log を統計算出
webalizer
ここで、上記の
OutputDir /var/www/webalizer
で指定したディレクトリを URI として Web ブラウザで表示させる
http://www.example.com/webalizer/
統計結果が正常に表示されれば成功


.2 統計算出の定期実行


Debian では自動で cron に登録されるため、手作業での追加は不要と なっている

/etc/cron.daily に以下が配置される
-rwxr-xr-x 1 root root 1491 2月 6 2012 webalizer
crontab を見る限り、毎日 6:25 に /usr/bin/webalizer が自動実行される事に なる
root:/etc# more crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
場合に よっては適宜変更したい人も いるかも知れない



6. 関連 URI


webalizerの設定 (Web Log アナライザ)

公開 : 2014年6月2日
戻る
pagetop