LoginSignup
16
14

More than 5 years have passed since last update.

fluentdが読み込むtd-agent.confのパース結果を調査する

Last updated at Posted at 2014-03-05

追記: もっと手軽に確認できるものとしてfluent-formatという便利gemがあると@sonotsさんに教えていただいた。

fluentdが読み込むtd-agent.confのパース結果を知りたい。

/var/log/td-agent/td-agent.log を読んで、
<ROOT> から始まる行を探して確認する、ということはせず、
fluent-debug コマンドを利用し確認する。

確認した環境は以下のとおり

td-agent deb パッケージ、公式ではUbuntu 13.04をサポートしていないので、
Ubuntu 12.04 LTSを利用しましょう

fluent-debug

fluent-debugと戯れる を参考にしました。

以下のような形でtd-agent.confを作成する。
includeなど外部ファイルの読み込み指定もテストを兼ねて入れている。

td-agent.confのパスは/etc/td-agent/td-agent.conf とする

td-agent.conf
include test.conf

<source>
  type forward
</source>

<source>
  type http
  port 8888
</source>

include test2.conf

<source>
  type debug_agent
  bind 127.0.0.1
  port 24230
</source>

td-agent.confでincludeしているtest.conf , test2.conf については
以下のような形にしている

test.conf
<match hoge.fuga.**>
  source file
  path /var/log/td-agent/test.log
</match>
test2.conf
<match huge.muga.*>
  type copy

  <store>
    type mongo
    database huge
    collection muga
  </store>

  <store>
    type file
    path /var/log/td-agent/test2.log
  </store>
</match>

準備はできた。

fluent-debugを立ち上げ、確認する

/usr/lib/fluent/ruby/bin/ 以下に、fluent-debugコマンドが展開されているので、立ち上げる。

> /usr/lib/fluent/ruby/bin/fluent-debug
Connected to druby://127.0.0.1:24230.
Usage:
    Engine.match('some.tag').output  : get an output plugin instance
    Engine.sources[i]                : get input plugin instances
    Plugin.load_plugin(type,name)    : load plugin class (use this if you get DRb::DRbUnknown)

irb(main):001:0>

fluentdの設定ファイルを読み込んでパースしているのは
ここの箇所で、Parser.readを呼び出しているのはここだ

...ということで、Fluent::Config.read を呼び出し、
readメソッドに対して/etc/td-agent/td-agent.conf ファイルを指定する。

> irb(main):001:0> puts Fluent::Config.read '/etc/td-agent/td-agent.conf'
<ROOT>
  <match hoge.fuga.**>
    source file
    path /var/log/td-agent/test.log
  </match>
  <source>
    type forward
  </source>
  <source>
    type http
    port 8888
  </source>
  <match huge.muga.*>
    type copy
    <store>
      type mongo
      database huge
      collection muga
    </store>
    <store>
      type file
      path /var/log/td-agent/test2.log
    </store>
  </match>
  <source>
    type debug_agent
    bind 127.0.0.1
    port 24230
  </source>
</ROOT>

include順序についても、途中でinclude test2.conf と差し込んだところについて
きちんとparseされてる。

fluent-debugをきちんと使いたい。

検証環境を用意するのがだるい場合

このVagrantfileを利用すると良いかも。
そして、以下のコマンドを叩く。(要Vagrantインストール)

> vagrant up server
> vagrant ssh server
> sudo su - anoonna
> fluent-debug
16
14
2

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
16
14