你能在配置文件中使用环境变量来获得流利吗?

Dan*_*cia 8 environment-variables fluentd

我想知道如何在Fluentd配置中使用env vars,我试过:

<match **>
type elasticsearch
logstash_format true
logstash_prefix $ENV_VAR
host ***
port ***
include_tag_key true
tag_key _key
</match>
Run Code Online (Sandbox Code Playgroud)

但它不起作用,任何想法?

Kiy*_*ura 14

编辑:

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

如果您将"--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>
Run Code Online (Sandbox Code Playgroud)

旧的,kludgey答案就在这里.

  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>
Run Code Online (Sandbox Code Playgroud)

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

  • --use-v1-config 现在是默认设置,因此您不必手动指定它。 (2认同)
  • 今天发现了这个。[Fluentd 常见问题解答](https://docs.fluentd.org/quickstart/faq) 并搜索“如何使用环境变量” (2认同)