拦截器位于 source
和 channel
之间,用于拦截修改和删除 event
,多个拦截器可一起使用;
假如想要知道日志采集来源于哪台机器,可以增加一个 Host Interceptor
,配置文件如下:

Host Interceptor
将当前 agent
所在机器的 ip
或者 hostname
加入到 event
的 header
中, key
为: host
,值为当前机器的 ip
或者 hostname
。
粗体为必配属性,其余为可配选项;
属性值 | 默认值 | 说明 |
---|---|---|
**type ** | – | 必须为 host |
useIP | ture | 为 true 使用 ip , false 使用 hostname |
UUID Interceptor
UUID 拦截器,基于该拦截器,可以为每一个 event
生成一个通用唯一的标识符并配置在 header
中
属性值 | 默认值 | 说明 |
---|---|---|
**type ** | – | 必须为 org.apache.flume.sink.solr.morphline.UUIDInterceptor$Builder |
Search and Replace Interceptor
此拦截器基于正则表达式提供简单的基于字符串的搜索和替换功能(针对 event body
)。
属性值 | 默认值 | 说明 |
---|---|---|
**type ** | – | 必须为 search_replace |
searchPattern | – | 匹配的正则表达式 |
replaceString | – | 替换值 |
Regex Filtering Interceptor
正则过滤拦截器,该拦截器使用正则表达式匹配原始 event body
中的内容,通过匹配结果和相关配置项来决定是否过滤之。
属性值 | 默认值 | 说明 |
---|---|---|
**type ** | – | 必须为 regex_filter |
regex | ”.*” | 匹配的正则表达式 |
Regex Ext\fractor Interceptor
正则提取拦截器,该拦截器使用正则表达式提取原始 event body
中的内容。
属性值 | 默认值 | 说明 |
---|---|---|
**type ** | – | 必须为 regex_filter |
regex | – | 匹配的正则表达式 |
serializers | – | 使用空格分隔的序列化名称 |
serializers..name | – | 序列化名称值 |
测试:
使用拦截器过滤目录下文件中不以 y.
开头的内容
配置如下:
# Define source, channel, sink #agent名称为a1 a1.sources = r1 a1.channels = c1 a1.sinks = k1 # Define source #source类型配置为avro,监听8888端口,后台会自动发送数据到该端口 #拦截后台发送过来的数据,将y.开头的保留下来 a1.sources.r1.type = avro a1.sources.r1.channels = c1 a1.sources.r1.bind = 0.0.0.0 a1.sources.r1.port = 8888 a1.sources.r1.interceptors = i1 a1.sources.r1.interceptors.i1.type = regex_filter a1.sources.r1.interceptors.i1.regex = y.* #a1.sources.r1.interceptors.i1.excludeEvents = false # Define channel #channel配置为memery a1.channels.c1.type = memory a1.channels.c1.capacity = 100 # Define sink #落地到 hdfs://localhost:9000/flume目录下 #根据时间落地,3s #数据格式DataStream a1.sinks.k1.channel = c1 a1.sinks.k1.type = hdfs a1.sinks.k1.hdfs.path = hdfs://localhost:9000/flume a1.sinks.k1.hdfs.rollInterval = 3 a1.sinks.k1.hdfs.fileType=DataStream
评论 抢沙发