地方エンジニアの学習日記

興味ある技術の雑なメモだったりを書いてくブログ。たまに日記とガジェット紹介。

【Fluentd】copyモジュール

fluentdで複数のシステムへログを転送したいときのTips。copyモジュールを使うという話。

docs.fluentd.org

<source>
  type tail
  path /var/log/myapp/nginx/access.log
    ...
  tag myapp.nginx.access
</source>

# Output
<match myapp.nginx.access>
  type    norikra
  norikra xxx.xxx.xxx.xxx:xxxxx
    ...
</match>
<match myapp.nginx.access>
  type elasticsearch
  host xxx.xxx.xxx.xxx
  port xxxx
    ...
</match>

...が, この書き換えてしまうと, 上に書かれたtype norikraの設定は有効になるのですが, 下のtype elasticsearchの設定は一切反映されず, fluentdからElasticsearchに対してログが送られなくなってしまいます.

こういう場合は, fluentdのcopyプラグインを使って, 次のように書けば期待通りに動いてくれます.

<match myapp.nginx.access>
  type copy
  <store>
    type    norikra
    norikra xxx.xxx.xxx.xxx:xxxxx
      ...
  </store>
  <store>
    type elasticsearch
    host xxx.xxx.xxx.xxx
    port xxxx
      ...
  </store>
</match>