首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >fluentd:多个过滤器和匹配的一个源码

fluentd:多个过滤器和匹配的一个源码
EN

Stack Overflow用户
提问于 2018-12-28 23:20:59
回答 2查看 4.3K关注 0票数 7

我有消息来源:

代码语言:javascript
运行
复制
<source>
    @type tail
    tag service
    path /tmp/l.log
    format json
    read_from_head true
</source>

我想对它做几个过滤器,并将它match到几个输出:

代码语言:javascript
运行
复制
<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。我能让它从一个源定义开始工作吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-05 12:24:47

您可以尝试使用插件copyrelabel来实现这一点。示例配置如下所示。

代码语言:javascript
运行
复制
//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示例文章有更多的方法可以通过重写标签等来实现,但对我来说,我喜欢使用标签,上面的内容看起来很简单。

我已经测试了上面的配置,它工作正常。让我知道你的想法:)。

票数 6
EN

Stack Overflow用户

发布于 2021-01-20 18:26:00

我和rewrite_tag_filter一起做的。

首先,我用TCP创建了source

代码语言:javascript
运行
复制
<source>
  @type tcp
  tag tcp.price-parser
  port 20001
  bind 0.0.0.0
  <parse>
    @type json
  </parse>
</source>

第二步是将tcp.price-parcer标签和重写标签与JSON数据进行匹配

代码语言:javascript
运行
复制
<match tcp.price-parser>
  @type rewrite_tag_filter
  <rule>
    key tag
    pattern /(info|error)/
    tag $1.${tag}
  </rule>
</match>

它的重要部分是设置rule并匹配它。如果不匹配,则fluentd不会继续。所以我的keytag。这个密钥来自JSON。例如JSON:

{"tag":"info","message":"My first message"}

和带有/(info|error)/值的规则pattern regex JSON tag键。如果找到infoerror,我们可以重写fluentd tag。所以tag $1.${tag}等同于info.tcp.price-parsererror.tcp.price-parser

现在你可以匹配重写标签了

代码语言:javascript
运行
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53960655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档