五、正则过滤拦截器
功能:过滤数据
1.配置flume-正则过滤拦截器的配置文件
flume-filter.conf
#1 agent a1.sources = r1 a1.sinks = k1 a1.channels = c1
#2 source a1.sources.r1.type = exec a1.sources.r1.command = tail -F /opt/plus
#正则过滤拦截器 a1.sources.r1.interceptors = i1 a1.sources.r1.interceptors.i1.type = regex_filter a1.sources.r1.interceptors.i1.regex = ^A.* #如果excludeEvents设为false,表示过滤掉不是以A开头的events。 #如果excludeEvents设为true,则表示过滤掉以A开头的events。 a1.sources.r1.interceptors.i1.excludeEvents = true
a1.sinks.k1.type = logger
a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100
a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1 |
2.监控文件安排妥当之后,执行该配置文件
[root@bigdata111 myconf]# flume-ng agent -c ../conf/ -n a1 -f flume-filter.conf -Dflume.root.logger==INFO,console
3.查看效果
1)向/opt/plus文件里添加以A为开头的内容,文件内容如下:
2)执行结果-查看logger:
3)由logger反映出来的结果可以看出正则过滤拦截器已经将监控文件plus中的倒数第二和第三行的以A为开头的内容过滤掉了。
这个过滤是针对监控文件的每行来说的-即一个event代表着监控文件的一行内容
4)下面再向plus文件追加一行数据:
[root@bigdata111 opt]# echo kA Ak >> plus
监控的logger显示出了该行,并没有将其过滤掉:
5)下面将excludeEvents参数改成false-只接收以A为开头的event,即:过滤掉不是以A为开头的event
#如果excludeEvents设为false,表示过滤掉不是以A开头的events。 #如果excludeEvents设为true,则表示过滤掉以A开头的events。 a1.sources.r1.interceptors.i1.excludeEvents = false |
查看logger:
可以看到传到日志里的只有以A为开头的行的内容,其他的都被过滤掉了。