たごもりすメモ

コードとかその他の話とか。

UPDATE: fluent-plugin-config-expander and fluent-plugin-forest

先日 fluent-plugin-forest を書いたあとpatchをもらって __HOSTNAME__ というプレースホルダをサポートしたりしてた。
で、こないだ config-expander を書いたときに「ホスト名を置換できるプレースホルダを組込みで入れようかな? まあ out_forest あるしいいか……」と思ってスルーしてた、が、forestはoutput pluginにしか使えなくて残念だなーということをこのblogエントリを見て思ったのでした。

fluentdで自ホスト名を自動でタグにするの巻 - アルパカDiary

ということで、config_expander でも __HOSTNAME__ というプレースホルダを展開できるようにしてみた。
ついでにtwitter上で見掛けた「__hoge__ より ${bar} なプレースホルダの方がいい」という意見を取り入れましてどっちでも展開できるようにしてアップデートしたものを config-expander ならびに forest 両方でリリースしておいた。

fluent-plugin-config-expander | RubyGems.org | your community gem host
fluent-plugin-forest | RubyGems.org | your community gem host

ということで、上記blogエントリの設定例は以下のように in_config_expander 一発で書けます。

<source>
  type config_expander
  <config>
    type tail
    format /^(?<date>[^\t]+)\t(?<cpu-usr>[^\t]+)\t(?<cpu-sys>[^\t]+)\t(?<cpu-idl>[^\t]+)\t(?<cpu-wai>[^\t]+)\t(?<cpu-hiq>[^\t]+)\t(?<cpu-siq>[^\t]+)\t(?<la-1m>[^\t]+)\t(?<la-5m>[^\t]+)\t(?<la-15m>[^\t]+)\t(?<mem-used>[^\t]+)\t(?<mem-buff>[^\t]+)\t(?<mem-cach>[^\t]+)\t(?<mem-free>[^\t]+)\t(?<dsk-read>[^\t]+)\t(?<dsk-writ>[^\t]+)\t(?<io-read>[^\t]+)\t(?<io-writ>[^\t]+)\t(?<net-recv>[^\t]+)\t(?<net-send>[^\t]+)/
    path /tmp/dstat.log
    tag dstat.Tclmdrn.__HOSTNAME__ # もしくは dstat.Tclmdrn.${hostname}
  </config>
</source>

べんり!