LoginSignup
10
11

More than 5 years have passed since last update.

FluentdのFilterが効かなくて困ったら書く順番だった

Last updated at Posted at 2015-07-21

Fluentdで「とあるログを受け取ってある条件を満たしたものをhipchatに投げる」というのを書いている時に、Filterが効かなくて(正規表現がうまく効かなくて?)丸一日くらいうがーーーーーーってなってたら、書く順番が違ったという話。

td-agent.conf
<source>
  type http
  port 8888
</source>

<match sakaimo.**>
  type file
  path /var/log/td-agent/sakaimo.log
</match>

<filter sakaimo.**>
  type grep
  regexp1 message ^2015
</filter>

↑こう書いていて、

# curl -X POST -d 'json={"message":"2015-07-21 for test"}' http://localhost:8888/sakaimo.test

を実行したら sakaimo.log に出力されたのでウハハハよゆーだなて思ってたです。

念のため条件に合わないパターンも試してみようと思って、

# curl -X POST -d 'json={"message":"test"}' http://localhost:8888/sakaimo.test

でやってみたら、これも出力されちゃったのです。( ゜Д゜;)!?
Filter効いてない!正規表現できてない!って思ったです。

~ ここから丸一日悩む ~

こうしたらちゃんと動きました。

<source>
  type http
  port 8888
</source>

<filter sakaimo.**>
  type grep
  regexp1 message ^2015
</filter>

<match sakaimo.**>
  type file
  path /var/log/td-agent/sakaimo.log
</match>

結論

filterディレクティブはmatchディレクティブより前に書くこと!!絶対だぞ!

ちなみに

filter
match
source

の順番で書いてもfilterが効いて動作しましたとさ。

10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11