编辑:
这里是一个更好的解决方案:
如果传递 “--use-V1-配置” 选项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>
老,kludgey答案就在这里。
- 安装
fluent-plugin-record-reformer
和fluent-plugin-forest
- 更新你的配置如下。
<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 **>
那里。这将捕捉所有事件并导致难以调试的行为。
从https://groups.google.com/forum/#!topic/fluentd/z-1vIsQ4kHU您需要在/ etc/default/td-agent中保留--use-v1-config的环境变量'像这样:'export FOO =“foobar”' – arun 2015-04-20 22:22:11
/etc/default/td-agent用于debian系列。 对于redhat系列,请改用/ etc/sysconfig/td-agent。 – sMiLo 2016-11-24 00:52:07