2014-12-01 115 views

回答

9

編輯:

這裏是一個更好的解決方案:

如果傳遞 「--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答案就在這裏。

  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 **>那裏。這將捕捉所有事件並導致難以調試的行爲。

+0

從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

+0

/etc/default/td-agent用於debian系列。 對於redhat系列,請改用/ etc/sysconfig/td-agent。 – sMiLo 2016-11-24 00:52:07

相關問題