千家信息网

Fluentd路由的示例分析

发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,这篇文章主要为大家展示了"Fluentd路由的示例分析",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"Fluentd路由的示例分析"这篇文章吧。简单场景:单
千家信息网最后更新 2025年02月04日Fluentd路由的示例分析

这篇文章主要为大家展示了"Fluentd路由的示例分析",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"Fluentd路由的示例分析"这篇文章吧。

  1. 简单场景:单输入->过滤器->输出


      @type forward
    @type record_transformer hostname "#{Socket.gethostname}"
    @type file # ...

    forward接收tcp消息,record_transformer给日志增加一个hostname字段,输出到file


  2. 两个输入

      @type forward
    @type tail tag system.logs # ...
    @type record_transformer hostname "#{Socket.gethostname}"
    @type file # ...

    较上一个示例,增加了一个tail输入,tail产生的事件直接写文件。


  3. 输入->过滤器->带标签的输出

      @type forward
    @type dstat @label @METRICS # dstat events are routed to # ...
    @type record_transformer # ...
    @type file # ...
    @type elasticsearch # ...

    forward产生的事件处理流程不变,dstat直接跳转至@METRICS指定的label,写入elasticsearch


  4. 改写tag重新路由

      @type route  remove_tag_prefix worker  add_tag_prefix metrics.event
    copy # For fall-through. Without copy, routing is stopped here. copy @label @BACKUP
    @type stdout
    @type file path /var/log/fluent/backup

    route插件将worker标记的事件重新标记为metrics.event,并重新发送事件给路由引擎,事件进入两个处理分支:输出到stdout;写入file



  5. 根据record内容重新路由

      @type forward
    # event example: app.logs {"message":"[info]: ..."} @type rewrite_tag_filter key message pattern ^\[(\w+)\] tag $1.${tag} # you can put more
    # send mail when receives alert level logs @type mail # ...
    # other logs are stored into file @type file # ...

    forward产生的事件由rewrite_tag_filter处理,提取record中的[log_level],添加到原tag之前,生成新的tag。事件再次进入路由引擎,alert开头的tag标记的事件,通过mail处理;其他类型的事件写入file


  6. 重新路由到指定label

      @type forward
    @type copy @type forward # ... @type relabel @label @NOTIFICATION
    @type grep regexp1 message ERROR
    @type mail
使用relabel插件,直接将事件路由到@NOTIFICATION指定的label处理。relabel不修改事件的tag。

以上是"Fluentd路由的示例分析"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0