Last active
December 18, 2015 12:59
-
-
Save ephemeralsnow/5786537 to your computer and use it in GitHub Desktop.
source, match の記述順序の解釈ミスでハマったこと
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# ※追記 | |
################################################################################ | |
in_tail -> out_forward -> in_forward -> out_file | |
の動作確認をしたかったが、2パターンとも期待とは異なっていたことが判明。 | |
NGとしていたパターンは常に <match forward.p.**> にマッチし、 | |
in_tail -> out_forward -> in_forward -> out_forward -> in_forward -> ... とループする。 | |
OKとしていたパターンは常に <match forward.p.java-pd.access> にマッチし、 | |
in_tail -> out_file となり out_forward -> in_forward が動作していなかった。 | |
################################################################################ | |
# やりたいこと | |
################################################################################ | |
ログを特定のサーバーへ集約させるために | |
localhost で in_forward, out_forward を動作確認 | |
################################################################################ | |
# 環境 | |
################################################################################ | |
myuzuki@dev-debian:~$ ruby -v | |
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-linux] | |
myuzuki@dev-debian:~$ gem list | |
*** LOCAL GEMS *** | |
bigdecimal (1.2.0) | |
bundler (1.3.5) | |
cool.io (1.1.0) | |
fluentd (0.10.35) | |
http_parser.rb (0.5.3) | |
io-console (0.4.2) | |
iobuffer (1.1.2) | |
json (1.7.7) | |
minitest (4.3.2) | |
msgpack (0.5.5) | |
psych (2.0.0) | |
rake (0.9.6) | |
rdoc (4.0.0) | |
test-unit (2.0.0.0) | |
yajl-ruby (1.1.0) | |
################################################################################ | |
# /home/myuzuki/td-agent-ng.conf | |
# include config.d/*.conf で、fluentd起動時に出力された内容 | |
# ※Dir.glob() が順序保証していないのか、別環境では異なる順序になり再現せず | |
################################################################################ | |
<match forward.p.**> | |
type forward | |
heartbeat_type tcp | |
buffer_type file | |
buffer_path /var/log/td-agent/p-forward.buf | |
flush_interval 10s | |
<server> | |
name localhost | |
host 127.0.0.1 | |
</server> | |
<secondary> | |
type file | |
path /var/log/td-agent/p-forward.err | |
</secondary> | |
</match> | |
<source> | |
type tail | |
path /var/log/java-pd/access.log | |
pos_file /var/log/td-agent/p-java-pd.pos | |
tag forward.p.java-pd.access | |
format /^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) (?<method>[A-Z]+) (?<url>[^ ]+)$/ | |
time_format %Y-%m-%d %H:%M:%S,%L | |
</source> | |
<source> | |
type forward | |
</source> | |
<match forward.p.java-pd.access> | |
type file | |
path /var/log/td-agent/p-aggregate-java-pd.log | |
</match> | |
################################################################################ | |
# /home/myuzuki/td-agent-ok.conf | |
# 個別にincludeし、fluentd起動時に出力された内容 | |
################################################################################ | |
<source> | |
type forward | |
</source> | |
<match forward.p.java-pd.access> | |
type file | |
path /var/log/td-agent/p-aggregate-java-pd.log | |
</match> | |
<source> | |
type tail | |
path /var/log/java-pd/access.log | |
pos_file /var/log/td-agent/p-java-pd.pos | |
tag forward.p.java-pd.access | |
format /^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) (?<method>[A-Z]+) (?<url>[^ ]+)$/ | |
time_format %Y-%m-%d %H:%M:%S,%L | |
</source> | |
<match forward.p.**> | |
type forward | |
heartbeat_type tcp | |
buffer_type file | |
buffer_path /var/log/td-agent/p-forward.buf | |
flush_interval 10s | |
<server> | |
name localhost | |
host 127.0.0.1 | |
</server> | |
<secondary> | |
type file | |
path /var/log/td-agent/p-forward.err | |
</secondary> | |
</match> | |
################################################################################ | |
# /var/log/java-pd/access.log | |
# fluentd起動後に配置したファイル(fluentd起動前は存在せず) | |
################################################################################ | |
2013-06-14 18:08:02,563 GET http://localhost/ | |
2013-06-14 18:09:54,137 GET http://localhost/index.htm | |
2013-06-14 18:09:56,313 GET http://localhost/index.html | |
################################################################################ | |
# fluentd -c td-agent-ng.conf の実行結果(NGパターン) | |
################################################################################ | |
/var/log/td-agent/p-forward.buf.forward.p.java-pd.access.***.log | |
上記ファイルが作成され、ファイル内にログの内容が含まれているが、 | |
数分待っても期待している動作(forward)がおこなわれないように見える。 | |
(p-aggregate-java-pd.log が作成されない) | |
################################################################################ | |
# fluentd -c td-agent-ok.conf の実行結果(OKパターン) | |
################################################################################ | |
/var/log/td-agent/p-aggregate-java-pd.log.20130614.*** | |
↓ | |
/var/log/td-agent/p-aggregate-java-pd.log.20130614_0.log | |
短い時間で上記ファイルが作成され、期待している動作(forward)がおこなわれる。 | |
(p-aggregate-java-pd.log が作成される) | |
################################################################################ | |
# 疑問 | |
################################################################################ | |
NGパターンで <match forward.p.**> ディレクティブの | |
buffer_type file | |
buffer_path /var/log/td-agent/p-forward.buf | |
は機能しているが、 forward が機能していないように見えた。 | |
source, match の順序の問題なら、 | |
バッファファイルが作られている(<match forward.p.**> が一部機能している)のは | |
中途半端なようにも思えるが、意図された挙動になっているのか? | |
※include の書き方を変えて回避できたので、ひとまず問題なし |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment