你可以在配置文件中使用流畅的环境变量 [英] Can you use environment variables in config file for fluentd
本文介绍了你可以在配置文件中使用流畅的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< match **>
type elasticsearch
logstash_format true
logstash_prefix $ ENV_VAR
主机***
端口***
include_tag_key true
tag_key _key
< / match>
但它不起作用,任何想法?
解决方案
编辑:
这是一个更好的解决方案:
如果您将--use-v1-config选项传递给Fluentd,则可以使用#{ENV ['env_var_name']这样:
< match foobar。**> #ENV [FOO]是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 。世界>键入record_reformer标签$ {ENV [FOO]} $ {tag_prefix [-1]}#将env变量添加为标签前缀< / match>< match foobar。**> #ENV [FOO]是foobar类型林子类型elasticsearch< template> logstash_prefix $ {tag_parts [0]} logstash_format true include_tag_key true tag_key _key host **** port ****< / template>< / match>
具体而言,请勿使用< match **>
。这将捕获所有事件,并将导致难以调试的行为。
I was wondering how to use env vars in the Fluentd config, I tried:
<match **>
type elasticsearch
logstash_format true
logstash_prefix $ENV_VAR
host ***
port ***
include_tag_key true
tag_key _key
</match>
but it doesn't work, any idea?
解决方案
EDIT:
Here is a much better solution:
If you pass "--use-v1-config" option to Fluentd, this is possible with the "#{ENV['env_var_name']" like this:
<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>
Old, kludgey answer is here.
- Install
fluent-plugin-record-reformer
andfluent-plugin-forest
- Update your config as follows.
<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>
In particular, do NOT use <match **>
there. That would catch all events and will lead to behaviors that are hard to debug.
这篇关于你可以在配置文件中使用流畅的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文