flume interceptor使用

Timestamp Interceptor

时间戳拦截器,将当前时间戳(毫秒)加入到events header中,key名字为:timestamp,值为当
前时间戳

参数默认值描述
type取值为timestamp,也可以使用类名的全路径
preserveExistingfalse如果设置为true,若事件中报头已经存在,不会替换报头同名key的值
a3.sources.r1.interceptors = ts //此名称自定义
a3.sources.r1.interceptors.ts.type=timestamp
a3.sources.r1.interceptors.ts.preserveExisting=false

效果样例: Event: { headers:{timestamp=1551589570711} body: 31 0D 1. }

Host Interceptor

主机名拦截器。将运行Flume agent的主机名或者IP地址加入到events header中,key名字为:host(也可自定义)

参数默认值描述
type取值为host
hostHeaderhost在header中插入的key名称,可选
useIPtrue如果设置为false,hostHeader键设为主机名,true则为主机IP
preserveExistingfalse如果设置为true,若事件中报头已经存在,不会替换报头同名key的值
a3.sources.r1.interceptors = host
a3.sources.r1.interceptors.host.type=host
a3.sources.r1.interceptors.host.hostHeader=jy //此名称可自定义,不配置则默认为"host"
a3.sources.r1.interceptors.host.userIP=false
a3.sources.r1.interceptors.host.preserveExisting=false

效果样例:Event: { headers:{jy=192.168.1.68} body: 63 6A 79 0D cjy. }

Static Interceptor

静态拦截器,用于在events header中加入一组静态的key和value。

参数默认值描述
type取值为static
keykey在header中插入的静态key名称
valuevaluekey对应的静态value
preserveExistingfalse如果设置为true,若事件中报头已经存在,不会替换报头同名key的值
a3.sources.r1.interceptors = sc
a3.sources.r1.interceptors.sc.type=static
a3.sources.r1.interceptors.sc.key=name
a3.sources.r1.interceptors.sc.value=cjy
a3.sources.r1.interceptors.sc.preserveExisting=false

效果样例:Event: { headers:{name=cjy} body: 68 61 68 61 68 61 68 61 0D hahahaha. }

UUID Interceptor

UUID拦截器,用于在每个events header中生成一个UUID字符串,例如:b5755073-77a9-43c1-8fad-b7a586fc1b97。生成的UUID可以在sink中读取并使用

参数默认值描述
type取值为org.apache.flume.sink.solr.morphline.UUIDInterceptor$Builder,表示为每个event随机产出uuid值
headerName在header中插入的uuid key名称
prefixuuid key的值的固定前缀,可选
preserveExistingtrue如果设置为true,若事件中报头已经存在,不会替换报头同名key的值
a3.sources.r1.interceptors = uu
a3.sources.r1.interceptors.uu.type=org.apache.flume.sink.solr.morphline.UUIDInterceptor$Builder
a3.sources.r1.interceptors.uu.headerName=uid
a3.sources.r1.interceptors.uu.prefix=player_
a3.sources.r1.interceptors.uu.preserveExisting=false

效果样例:Event: { headers:{uid=player_46ee9168-0ef3-4e91-866d-342a27f88c85} body: 63 6A 79 0D cjy. }

Regex Filtering Interceptor

正则过滤拦截器,通过正则来清洗数据

参数默认值描述
type取值为REGEX_FILTER
regex.*匹配的event的正则表达式,不匹配\n
excludeEventsfalse默认收集匹配到的事件。如果为true,则会删除匹配到的event,收集未匹配到的。
a3.sources.r1.interceptors = re
a3.sources.r1.interceptors.re.type=regex_filter
a3.sources.r1.interceptors.re.regex=(ERROR)
a3.sources.r1.interceptors.re.excludeEvents=true

效果样例:过滤掉包含"ERROR"字符串的event,如aERROR123,整个event将被删除

Regex Extractor Interceptor

正则抽取拦截器,通过正则表达式来在header中添加指定的key,value则为正则匹配的部分

参数默认值描述
type取值为REGEX_EXTRACTOR
regex匹配的event的正则表达式,不匹配\n
serializers定义匹配组(正则匹配之后的值作为header的值,如分组为s1、s2
serializers.s1.typedefalut序列化value的类,可选
serializers.s1.namekey的名称,value为s1的匹配值

flume提供俩种内置序列化类:org.apache.flume.interceptor.RegexExtractorInterceptorPassThroughSerializer ,default为此类
org.apache.flume.interceptor.RegexExtractorInterceptorMillisSerializer

a3.sources.r1.interceptors = re
a3.sources.r1.interceptors.re.type=regex_extractor
a3.sources.r1.interceptors.re.regex=(\\d+),(\\d+),.* //第一个分组分配为s1,第二个为s2...
a3.sources.r1.interceptors.re.serializers=s1 s2 //对应正则分组
a3.sources.r1.interceptors.re.serializers.s1.name=order_id
a3.sources.r1.interceptors.re.serializers.s2.name=user_id

效果样例:数据源:12345,756,abc
处理结果:Event: { headers:{user_id=756, order_id=12345} body: 31 32 33 34 35 2C 37 35 36 2C 61 62 63 0D 12345,756,abc. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值