六、正则抽取拦截器
功能:抽取匹配的数据放进header中--headers{hostname=bigdata111,ip=192.168.212.111}
1.配置flume-正则抽取拦截器配置文件
flume-extractor.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_extractor #hostname is bigdata111 ip is 192.168.212.111 a1.sources.r1.interceptors.i1.regex = hostname is (.*?) ip is (.*) #将获取到的数据放入s1和s2 a1.sources.r1.interceptors.i1.serializers = s1 s2 #将获取的数据起一个名字 a1.sources.r1.interceptors.i1.serializers.s1.name = hostname a1.sources.r1.interceptors.i1.serializers.s2.name = ip
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 |
注:正则抽取拦截器的headers不会出现在文件名和文件内容中
2.监控文件安排其妥当之后,执行配置文件
1)目前/opt/plus文件里的内容:

2)执行后的执行结果:

可以看出,正则抽取拦截器没有找到符合的数据,因此以上的headers集合中都是空的。
3)现在追加符合要求的数据行让其捕获到:
[root@bigdata111 opt]# echo hostname is bigdata111 ip is 192.168.212.111 >> plus
[root@bigdata111 opt]# echo hostname is bigdata111 ip is 192.168.212.111 >> plus
[root@bigdata111 opt]# echo hostname is bigdata111 ip is 192.168.212.111 >> plus
4)再查看logger:

能够看到:已经捕获了符合的数据,并将其放入headers中了。
浙公网安备 33010602011771号