Fluentd – 使用源标签作为索引

我有一个在Docker引擎上运行Fluentd和Elasticsearch的设置。 我有很多我想loginFluentd的服务。

我想要做的是为我运行的每个服务创build一个标签,并使用该标签作为Elasticsearch中的一个索引。 这是我有的设置:

<source> @type forward port 24224 bind 0.0.0.0 </source> <match docker.service1> @type elasticsearch host "172.20.0.3" port 9200 index_name service1 type_name fluentd flush_interval 10s </match> <match docker.service2> @type elasticsearch host "172.20.0.3" port 9200 index_name service2 type_name fluentd flush_interval 10s </match> 

等等。

这将是恼人的,必须包括一个新的匹配标签为我创build的每一个单一的服务,因为我希望能够添加新的服务,而无需更新我的stream利的configuration。 有没有办法做这样的事情:

 <source> @type forward port 24224 bind 0.0.0.0 </source> <match docker.**> @type elasticsearch host "172.20.0.3" port 9200 index_name $(TAG) type_name fluentd flush_interval 10s </match> 

我在哪里使用$(TAG)variables来表示我希望标签名称是索引的名称?

我试过这个从我在这里find的答案:$ {tag_parts [0]}。 这是从字面上打印成我的索引。 所以我的索引是“$ {tag_parts [0]}”。

提前致谢。

我发现我需要导入另一个Elasticsearch插件。 以下是我使用的匹配代码示例:

 <match> @type elasticsearch_dynamic host "172.20.0.3" port 9200 type_name fluentd index_name ${tag_parts[2]} flush_interval 10s include_tag_key true reconnect_on_error true </match> 

我已经导入了@elasticsearch_dynamic插件而不是@elasticsearch插件。 然后,我可以使用$ {tag_parts}的东西。

include_tag_key将标签包含在json数据中。

这有助于阅读文档