Fluentdを導入して、acesslogを収集し、Growthforcastで、ステータスコードやレスポンスのグラフを表示するまで




投稿日:

意外に簡単に設定が出来ます。

【事前準備】

・Fluentd(or td-agent)がインストール済みであること。
・Growthforcastがインストール済みであること。

【導入するプラグイン】

収集サーバでのFluentdでログの改変をしていく上で、いくつかプラグインを入れます。どれも有名どころで使う場面も多いと思います。それぞれ、集計サーバにてインストールしておきます。


■ out_file_alternative 

単純にログを様々な出力するプラグイン。結構重宝する。まさに、「ログを集約して一箇所で書く」が簡単にできるプラグイン。

・インストール
[html]# /usr/lib64/fluent/ruby/bin/gem install fluent-plugin-file-alternative[/html]

参考: 
#fluentd fluent-plugin-file-alternative released! – tagomorisのメモ置き場
https://github.com/tagomoris/fluent-plugin-file-alternative


■ fluent-plugin-sampling-filter

名前の通り、サンプリングをしてあげるプラグインです。リアルタイムにすべてのログをフィルターして統計を取ったりするのは、サーバへの負荷が高いために、全10個のうち1個をサンプリングをしてあげて、処理ができるようになります。

・インストール
[html]# /usr/lib64/fluent/ruby/bin/gem install fluent-plugin-sampling-filter
[/html]

参考:
fluent-plugin-sampling-filter and fluent-plugin-datacounter released! #fluentd – tagomorisのメモ置き場


■ fluent-plugin-datacounter

特定のパターンのデータの件数を取る事が出来ます。時間毎やタグ毎のカウントも可能です。

・インストール
[html]#/usr/lib64/fluent/ruby/bin/gem install fluent-plugin-datacounter[/html]

参考:
fluent-plugin-sampling-filter and fluent-plugin-datacounter released! #fluentd – tagomorisのメモ置き場


■ fluent-plugin-growthforecast

growthforecastへのデータ出力用のプラグインです。

・インストール
[html]#/usr/lib64/fluent/ruby/bin/gem install fluent-plugin-growthforecast[/html]

参考:
fluent-plugin-flowcounter および fluent-plugin-growthforecast released! #fluentd – tagomorisのメモ置き場


【構成】

■ WEBサーバ側

[html]# 特定accessログの取り込み
<source>
type tail
path /www/www.xxxxx.net/logs/access_log.%Y%m%d
pos_file /var/log/td-agent/httpd-access.pos
tag td.xx.xxxxx
format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<status>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<response_time>[^ ]*) "(?<cookie>[^ ]*)")?$/
time_format %d/%b/%Y:%H:%M:%S %z
</source>

# Output 集約サーバに送信します。
<match td.xx.xxxxx>
type forward
send_timeout 60s
recover_wait 10s
heartbeat_interval 1s
phi_threshold 8
hard_timeout 60s

<server># <= 送信先サーバーの指定
name server1
host 172.19.0.xx
port 24224
</server>
</match>

[/html]


■ ログ集約&出力サーバ

[html]
# Input ログの受付設定です。
<source>
type forward
port 24224
bind 0.0.0.0
</source>

# out_sampling_filter strongly recommended
#<match *.**>
# type sampling_filter
# interval 10
# remove_prefix accesslog
# add_prefix sampled
#</match>

<match td.xx.xxxxx>
type copy

# save as log format
<store>
type file_alternative
path /var/log/td-agent/access/test/%Y/%m/access.test1.%Y%m%d%H 
flush_interval 30s #180s
compress gzip
localtime
</store>

# filter for infra monitor
<store>
type rewrite_tag_filter
capitalize_regex_backreference yes
rewriterule1 path \.(gif|jpe?g|png|pdf|zip|css|js|ico)$ clear
rewriterule2 status ^(?!200)$ clear
rewriterule3 method ^(?!GET)$ clear
rewriterule4 path .* infra.monitor
</store>

</match>

<match infra.monitor>
type copy

# Count by status code
<store>
type datacounter
count_key status
aggregate all
tag gf.status_code
count_interval 300

pattern1 2xx ^2\d\d$
pattern2 3xx ^3\d\d$
pattern3 4xx ^4\d\d$
pattern4 5xx ^5\d\d$

</store>

# Count by responstime
<store>
type datacounter
count_key response_time
aggregate all
tag gf.response
count_interval 300

pattern1 0-100msec ^\d{1,5}$
pattern2 100-300msec ^[1-2]\d{5}$
pattern3 300-600msec ^[3-5]\d{5}$
pattern4 600msec-1sec ^[6-9]\d{5}$
pattern5 1-2sec ^1\d{6}$
pattern6 2-10sec ^[2-9]\d{6}$
pattern7 10sec_over ^\d{8,}$
</store>

</match>

#growthforecast
# 以下のようにデータを送ります。

<match gf.**>
type growthforecast
gfapi_url http://x.x.x.x:5125/infra/
service infra
tag_for section
remove_prefix gf
name_key_pattern .*_(rate|count|percentage)$
</match>

### Output
<match *.*>  
type file
path /var/log/td-agent/all_messages.log
time_slice_format %Y%m%d
time_format %Y%m%dT%H%M%S%z
</match>

# match fluent’s internal events
<match clear>
type null
</match>

[/html]






コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください