【Flume 1.6.0】五、Flume Interceptors

本文介绍了Apache Flume中几种常用的拦截器配置方法,包括TimestampInterceptor用于添加时间戳标签,HostInterceptor用于获取部署服务器的IP或主机名,StaticInterceptor用于自定义向header中添加键值对,便于后续的数据处理和分流。

一、Timestamp Interceptor

在event headers中,添加timestamp标签

[root@hftest0001 conf]# pwd
/opt/apache-flume-1.6.0-bin/conf

[root@hftest0001 conf]# vi s-exec_c-m_s-logger.conf 

agent.sources = exec_tail
agent.channels = memoryChannel
agent.sinks = loggerSink

agent.sources.exec_tail.type = exec
agent.sources.exec_tail.command = tail -F /opt/flume-data/exec-tail.log
agent.sources.exec_tail.channels = memoryChannel

agent.sources.exec_tail.interceptors = i1
agent.sources.exec_tail.interceptors.i1.type = timestamp
#agent.sources.exec_tail.interceptors.i1.preserveExisting = true

agent.sinks.loggerSink.type = logger
#agent.sinks.loggerSink.maxBytesToLog = 1
agent.sinks.loggerSink.channel = memoryChannel

agent.channels.memoryChannel.type = memory
agent.channels.memoryChannel.capacity = 100

===>结果
Event: { headers:{timestamp=1452668731658} body: 78 78                                           xx }


二、Host Interceptor

获取agent部署那台server的ip或是hostname,或添加到host标签中

[root@hftest0001 conf]# pwd
/opt/apache-flume-1.6.0-bin/conf
[root@hftest0001 conf]# vi s-exec_c-m_s-logger.conf 

agent.sources.exec_tail.type = exec
agent.sources.exec_tail.command = tail -F /opt/flume-data/exec-tail.log
agent.sources.exec_tail.channels = memoryChannel

agent.sources.exec_tail.interceptors = i1 i2
agent.sources.exec_tail.interceptors.i1.type = timestamp
#agent.sources.exec_tail.interceptors.i1.preserveExisting = true

agent.sources.exec_tail.interceptors.i2.type = host
#agent.sources.exec_tail.interceptors.i2.userIP = false                =>default:true 设置为false,则获取的值为hostname
#agent.sources.exec_tail.interceptors.i2.hostHeader = hostname        => default:header中key为host,可以设置更改
#agent.sources.exec_tail.interceptors.i2.preserveExisting = true

agent.sinks.loggerSink.type = logger
#agent.sinks.loggerSink.maxBytesToLog = 1
agent.sinks.loggerSink.channel = memoryChannel

agent.channels.memoryChannel.type = memory
agent.channels.memoryChannel.capacity = 100

===>result 
Event: { headers:{timestamp=1452669139164, host=${ip}} body: 78 78                                           xx }

三、Static Interceptor

自定义向header中添加k-v: 用途,如想知道events是那个dc的,那个country,那个city。也可以根据这些header信息,进行数据分流等等

[root@hftest0001 conf]# pwd
/opt/apache-flume-1.6.0-bin/conf
[root@hftest0001 conf]# vi s-exec_c-m_s-logger.conf 

#agent.sources.exec_tail.interceptors.i2.userIP = false
#agent.sources.exec_tail.interceptors.i2.hostHeader = hostname
#agent.sources.exec_tail.interceptors.i2.preserveExisting = true

agent.sources.exec_tail.interceptors.i3.type = static
agent.sources.exec_tail.interceptors.i3.key = country
agent.sources.exec_tail.interceptors.i3.value = USA

agent.sources.exec_tail.interceptors.i4.type = static
agent.sources.exec_tail.interceptors.i4.key = city
agent.sources.exec_tail.interceptors.i4.value = NEW_YORK


agent.sinks.loggerSink.type = logger
#agent.sinks.loggerSink.maxBytesToLog = 1
agent.sinks.loggerSink.channel = memoryChannel

agent.channels.memoryChannel.type = memory
agent.channels.memoryChannel.capacity = 100

===> result
Event: { headers:{timestamp=1452669538967, host=${IP}, city=NEW_YORK, country=USA} body: 78 78                                           xx }

四、Regex Filtering Interceptor


五、Regex Extractor Interceptor

转载于:https://my.oschina.net/u/204498/blog/601890

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值