我有消息来源:
<source>
@type tail
tag service
path /tmp/l.log
format json
read_from_head true
</source>
我想对它做几个过滤器,并将它match
到几个输出:
<source>
@type tail
tag service.pi2
path /tmp/out.log
format json
read_from_head true
</source>
<source>
@type tail
tag service.data
path /tmp/out.log
format json
read_from_head true
</source>
<filter service.data>
# some filtering
</filter>
<filter service.pi2>
# some filtering
</filter>
<match service.data>
@type file
path /tmp/out/data
</match>
<match service.pi2>
@type file
path /tmp/out/pi
</match>
到目前为止,为了让一切正常工作,我必须用不同的标签复制source
。我能让它从一个源定义开始工作吗?
发布于 2019-01-05 12:24:47
您可以尝试使用插件copy和relabel来实现这一点。示例配置如下所示。
//One Source
<source>
@type tail
tag service
path /tmp/l.log
format json
read_from_head true
</source>
//Now Copy Source Events to 2 Labels
<match service>
@type copy
<store>
@type relabel
@label @data
</store>
<store>
@type relabel
@label @pi2
</store>
</match>
//@data Label, you can perform desired filter and output file
<label @data>
<filter service>
...
</filter>
<match service>
@type file
path /tmp/out/data
</match>
</label>
//@pi2 Label, you can perform desired filter and output file
<label @pi2>
<filter service>
...
</filter>
<match service>
@type file
path /tmp/out/pi
</match>
</label>
这篇Routing示例文章有更多的方法可以通过重写标签等来实现,但对我来说,我喜欢使用标签,上面的内容看起来很简单。
我已经测试了上面的配置,它工作正常。让我知道你的想法:)。
发布于 2021-01-20 18:26:00
我和rewrite_tag_filter
一起做的。
首先,我用TCP
创建了source
<source>
@type tcp
tag tcp.price-parser
port 20001
bind 0.0.0.0
<parse>
@type json
</parse>
</source>
第二步是将tcp.price-parcer
标签和重写标签与JSON数据进行匹配
<match tcp.price-parser>
@type rewrite_tag_filter
<rule>
key tag
pattern /(info|error)/
tag $1.${tag}
</rule>
</match>
它的重要部分是设置rule
并匹配它。如果不匹配,则fluentd不会继续。所以我的key
是tag
。这个密钥来自JSON。例如JSON:
{"tag":"info","message":"My first message"}
和带有/(info|error)/
值的规则pattern
regex JSON tag
键。如果找到info
或error
,我们可以重写fluentd tag
。所以tag $1.${tag}
等同于info.tcp.price-parser
或error.tcp.price-parser
。
现在你可以匹配重写标签了
<match info.tcp.price-parser>
@type slack
token xoxb-***
channel price-parser
username la
icon_emoji :ghost:
message "%s"
message_keys message
flush_interval 5s
</match>
https://stackoverflow.com/questions/53960655
复制相似问题