使用拦截器过滤Flume中的日志文件

Shi*_*tar 3 hadoop flume

我有一个http服务器写日志文件然后我使用Flume首先加载到HDFS我想根据我的标题或正文中的数据过滤数据.我读到我可以使用带有正则表达式的拦截器来执行此操作,有人可以解释我需要做什么吗?我是否需要编写覆盖Flume代码的Java代码?

另外我想取数据并根据标题发送到另一个接收器(即source = 1转到sink1而source = 2转到sink2)这是怎么做的?

谢谢,

西蒙

Dmi*_*try 11

您不需要编写Java代码来过滤事件.使用正则表达式过滤拦截器来过滤正文与正则表达式匹配的事件:

agent.sources.logs_source.interceptors = regex_filter_interceptor
agent.sources.logs_source.interceptors.regex_filter_interceptor.type = regex_filter
agent.sources.logs_source.interceptors.regex_filter_interceptor.regex = <your regex>
agent.sources.logs_source.interceptors.regex_filter_interceptor.excludeEvents = true
Run Code Online (Sandbox Code Playgroud)

要基于标头路由事件,请使用多路复用通道选择器:

a1.sources = r1
a1.channels = c1 c2 c3 c4
a1.sources.r1.selector.type = multiplexing
a1.sources.r1.selector.header = state
a1.sources.r1.selector.mapping.CZ = c1
a1.sources.r1.selector.mapping.US = c2 c3
a1.sources.r1.selector.default = c4
Run Code Online (Sandbox Code Playgroud)

这里带有标题"state"="CZ"的事件进入通道"c1","state"="US" - "c2"和"c3",所有其他 - 到"c4".

这样,您还可以按标头过滤事件 - 只需将特定标头值路由到通道,即指向Null Sink.