11

我想知道如何在 Fluentd 配置中使用环境变量,我试过:

<match **>
type elasticsearch
logstash_format true
logstash_prefix $ENV_VAR
host ***
port ***
include_tag_key true
tag_key _key
</match>

但它不起作用,你知道吗?

4

1 回答 1

20

编辑:

这是一个更好的解决方案:

如果将“--use-v1-config”选项传递给 Fluentd,则可以使用“#{ENV['env_var_name']”,如下所示:

<match foobar.**> # ENV["FOO"] is foobar
  type elasticsearch
  logstash_prefix "#{ENV['FOO']}"
  logstash_format true
  include_tag_key true
  tag_key _key
  host ****
  port ****
</match>

旧的,笨拙的答案就在这里。

  1. 安装fluent-plugin-record-reformerfluent-plugin-forest
  2. 如下更新您的配置。

<match hello.world>
  type record_reformer
  tag ${ENV["FOO"]}.${tag_prefix[-1]} # adding the env variable as a tag prefix
</match>

<match foobar.**> # ENV["FOO"] is foobar
  type forest
  subtype elasticsearch
  <template>
    logstash_prefix ${tag_parts[0]}
    logstash_format true
    include_tag_key true
    tag_key _key
    host ****
    port ****
  </template>
</match>

特别是,不要在<match **>那里使用。这将捕获所有事件并导致难以调试的行为。

于 2014-12-02T23:08:11.813 回答