- http://blog.nomadscafe.jp/2011/12/growthforecast.html
- http://d.hatena.ne.jp/tagomoris/20120218/1329558305
- http://d.hatena.ne.jp/hogem/20120521/1337610385
cacti はcactiで便利だけど、設定するのに面倒だったりする一方でgrowthforecastはびっくりするぐらい簡単なのでとても素敵ですね。
ログを受け取るfluentd で type datacounter をstoreする設定まで完了している前提。
type datacounter で pattern1 2xx などと設定しておくとfluentの JSON 出力に、2xx_count, 2xx_rate, 2xx_percentage などが出てくるので、グラフにしたい値をtype growthforecast を指定するstore 内に設定する。
ここではを数を数える例なので *_count を指定。
- web server
<source>
type tail
#format apache
path /var/log/httpd/access.log
pos_file /var/log/fluent/access.log.pos
tag apache.access
format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<response_time>\d+))?$/
#format /(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<status>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<response_time>[^ ]*))?$/
time_format %d/%b/%Y:%H:%M:%S %z
</source>
<match apache.access>
#type file
#path /var/log/fluent/access
type forward
flush_interval 1
<server>
host 192.168.0.10
name logserver
port 24224
</server>
</match>
- fluentd log server
<source>
type forward
</source>
<match apacche.status>
<store>
type datacounter
count_interval 10
count_key code
tag apache_result.status
aggregate all
# patternX: X(1-9)
pattern1 2xx ^2\d\d$
pattern2 3xx ^3\d\d$
pattern3 4xx ^4\d\d$
pattern4 5xx ^5\d\d$
</store>
</match>
<match apache_result.status>
type copy
<store>
type stdout
</store>
<store>
type growthforecast
gfapi_url http://192.168.0.1:5125/api/
remove_prefix apache_result
service app
section apache
name_keys 2xx_count,3xx_count,4xx_count,5xx_count
</store>
</match>
これでgrowthforecast の app / apache 以下に
- status_2xx_count
- status_3xx_count
- status_4xx_count
- status_5xx_count
等が出来る。remove_prefix しているのは、グラフ内の文字列がapache_result.status_2xx_count と名前が長くなって見難くなるのが嫌なので。(もしくは apache.status 内の設定でtag status のようにprefixを付けないようにするか)
あとはgrowthforecast側で適当な名前で複合グラフを作成すれば良い。こんなのが間単に描ける。
補足
上のグラフで50x の割合多くね?と思われるかもしれませんが、確認用のために、cgiでrandomなstatus codeを返したログをfluentdに渡していただけなので、しょぼいサーバを運用しているとか、そういうわけではありません。

