这篇文章主要为大家展示了“Fluentd路由的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Fluentd路由的示例分析”这篇文章吧。
简单场景:单输入->过滤器->输出
<source> @type forward</source><filter app.**> @type record_transformer <record> hostname "#{Socket.gethostname}" </record></filter><match app.**> @type file # ...</match>
forward接收tcp消息,record_transformer给日志增加一个hostname字段,输出到file
两个输入
<source> @type forward</source><source> @type tail tag system.logs # ...</source><filter app.**> @type record_transformer <record> hostname "#{Socket.gethostname}" </record></filter><match {app.**,system.logs}> @type file # ...</match>
较上一个示例,增加了一个tail输入,tail产生的事件直接写文件。
输入->过滤器->带标签的输出
<source> @type forward</source><source> @type dstat @label @METRICS # dstat events are routed to <label @METRICS> # ...</source><filter app.**> @type record_transformer <record> # ... </record></filter><match app.**> @type file # ...</match><label @METRICS> <match **> @type elasticsearch # ... </match></label>
forward产生的事件处理流程不变,dstat直接跳转至@METRICS指定的label,写入elasticsearch
改写tag重新路由
<match worker.**> @type route remove_tag_prefix worker add_tag_prefix metrics.event <route **> copy # For fall-through. Without copy, routing is stopped here. </route> <route **> copy @label @BACKUP </route></match><match metrics.event.**> @type stdout</match><label @BACKUP> <match metrics.event.**> @type file path /var/log/fluent/backup </match></label>
route插件将worker标记的事件重新标记为metrics.event,并重新发送事件给路由引擎,事件进入两个处理分支:输出到stdout;写入file
根据record内容重新路由
<source> @type forward</source># event example: app.logs {"message":"[info]: ..."}<match app.**> @type rewrite_tag_filter <rule> key message pattern ^\[(\w+)\] tag $1.${tag} </rule> # you can put more <rule></match># send mail when receives alert level logs<match alert.app.**> @type mail # ...</match># other logs are stored into file<match *.app.**> @type file # ...</match>
forward产生的事件由rewrite_tag_filter处理,提取record中的[log_level],添加到原tag之前,生成新的tag。事件再次进入路由引擎,alert开头的tag标记的事件,通过mail处理;其他类型的事件写入file
重新路由到指定label
<source> @type forward</source><match app.**> @type copy <store> @type forward # ... </store> <store> @type relabel @label @NOTIFICATION </store></match><label @NOTIFICATION> <filter app.**> @type grep regexp1 message ERROR </filter> <match app.**> @type mail </match></label>
以上是“Fluentd路由的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/fluentd/blog/4354328