Skip to content

Instantly share code, notes, and snippets.

@sonots
Last active April 1, 2019 20:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonots/32937868f64f48bb3815 to your computer and use it in GitHub Desktop.
Save sonots/32937868f64f48bb3815 to your computer and use it in GitHub Desktop.
fluentd label and filter (1)
# fluent.conf
<source>
  type dummydata_producer
  tag dummy.data
  rate 500
  dummydata0 {\"type\":\"sample\",\"code\":50,\"format\":\"json string allowed\"}
  dummydata1 {\"message\":\"other format needed?\"}
  dummydata2 {\"comment\":\"N of dummydataN is number and not limited\"}
  @label @raw
</source>
$ bundle exec fluentd -c fluent.conf
~/src/github.com/fluent/fluentd/lib/fluent/config/parser.rb:47:in `parse!': parse error at fluentd.conf line 9 (Fluent::ConfigParseError)
        from /home/game/src/github.com/fluent/fluentd/lib/fluent/config/parser.rb:33:in `parse!'
        from /home/game/src/github.com/fluent/fluentd/lib/fluent/config/parser.rb:8:in `parse'
        from /home/game/src/github.com/fluent/fluentd/lib/fluent/config.rb:33:in `parse'

--use-v1-config が必須な旨のエラーメッセージが欲しいかな.

@sonots
Copy link
Author

sonots commented Aug 19, 2014

全メッセージにとりあえず flowcounter を当てる、とかやりたい。

# fluent.conf
<source>
  type dummydata_producer
  tag dummy.data
  rate 500
  dummydata0 {\"type\":\"sample\",\"code\":50,\"format\":\"json string allowed\"}
  dummydata1 {\"message\":\"other format needed?\"}
  dummydata2 {\"comment\":\"N of dummydataN is number and not limited\"}
  @label @raw
</source>

<label @raw>
  <filter **>
    type flowcounter
    count_keys *
    unit minute
    aggregate all
    tag flowcounter.worker.%HOST%:%PORT%
  </filter>
  <match **>
    type stdout
    @label @test
  </match>
</label>

filter はまだないようだ。残念。

2014-08-19 18:14:08 +0900 [warn]: parameter 'type' in <filter **>
  type flowcounter
  count_keys *
  unit minute
  aggregate all
  tag flowcounter.worker.%HOST%:%PORT%
</filter> is not used.

@sonots
Copy link
Author

sonots commented Aug 19, 2014

redirect (or relabel) できればイケるかな?

# fluent.conf
<source>
  type dummydata_producer
  tag dummy.data
  rate 500
  dummydata0 {\"type\":\"sample\",\"code\":50,\"format\":\"json string allowed\"}
  dummydata1 {\"message\":\"other format needed?\"}
  dummydata2 {\"comment\":\"N of dummydataN is number and not limited\"}
  @label @raw
</source>

<label @raw>
  <match **>
    type copy
    <store>
      type flowcounter
      count_keys *
      unit minute
      aggregate all
      tag flowcounter.worker.%HOST%:%PORT%
    </store>
    <store>
      type redirect
     @label @test
    </store>
  </match>
</label>

<label @test>
  type stdout
</label>

<match flowcounter.**>
  type stdout
</match>

redirect (or relabel) プラグインはまだない模様。。。残念。。。

2014-08-19 18:18:02 +0900 [error]: config error file="fluentd.conf" error="Unknown output plugin 'redirect'. Run 'gem search -rd fluent-plugin' to find plugins"

あと、<label> の下に type を直接書くとエラーだった。そうだった。

2014-08-19 18:18:15 +0900 [warn]: parameter 'type' in <label @test>
  type stdout
</label> is not used.

@sonots
Copy link
Author

sonots commented Aug 20, 2014

やりたいことの明文化。たとえば

<source>
  type forward
</source>

<match raw.app1.**>
  type grep
  input_key message
  regexp foo
  remove_tag_prefix raw
  add_tag_prefix grep
</match>

<match raw.app2.**>
  type grep
  input_key message
  regexp bar
  remove_tag_prefix raw
  add_tag_prefix grep
</match>

<match grep.**>
  type stdout
</match>

という設定があった場合に、これに対して全入力メッセージ(raw.**)にとりあえず flowcounter をあてる設定をたそうと思うと、以下のようにするしかなかった。

raw を raw2 に置換している箇所がちょこちょこあって、大変面倒.というか普通にミスる。

<source>
  type forward
</source>

<match raw.**>
  type copy
  <store>
    type flowcounter
    tag flowcounter
  </store>
  <store>
    type rewrite
    remove_prefix raw
    add_prefix raw2
  </store>
</match>

<match raw2.app1.**>
  type grep
  input_key message
  regexp foo
  remove_tag_prefix raw2
  add_tag_prefix grep
</match>

<match raw2.app2.**>
  type grep
  input_key message
  regexp bar
  remove_tag_prefix raw2
  add_tag_prefix grep
</match>

<match grep.**>
  type stdout
</match>

<match flowcounter>
  type stdout
</match>

ラベルをつかえると、これが次のようになる。<label @main> の中はインデントするだけですんでありがたい。

<source>
  type forward
  @label @raw
</source>

<label @raw>
  type copy
  <store>
    type flowcounter
    tag flowcounter
    @label @flowcounter
  </sotre>
  <store>
    type relabel
    @label @main
  </store>
<label>

<label @main>
  <match raw.app1.**>
    type grep
    input_key message
    regexp foo
    remove_tag_prefix raw
    add_tag_prefix grep
  </match>

  <match raw.app2.**>
    type grep
    input_key message
    regexp bar
    remove_tag_prefix raw
    add_tag_prefix grep
  </match>

  <match grep.**>
    type stdout
  </match>
</label>

<label @flowcounter>
  <match **>
    type stdtout
  </match>
</label>

さらに filter を使えると ... To be continued.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment