flume攔截器的使用

interceptors 攔截器

​ 可以攔截數據源 source 給數據源添加數據 header信息 爲了後續的數據的更加方便的使用

默認攔截器有:

1)Timestamp Interceptor

​ 在數據源上添加時間戳
​ headers:{timestamp=1554707017331}
​ key: timestamp
​ value:當前系統的時間戳

2)host interceptor

​ 攔截數據源 每一個event 在每一條數據的header中添加 hostname| ip
​ key: host
​ value : 當前主機的 hostname | ip

例子

指定當前agent a1的 sources sinks  channels 的別名
a1.sources = r1
a1.sinks = k1
a1.channels = c1

agent的數據源的
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

指定agent的sink的
a1.sinks.k1.type = logger

指定agent的通道
a1.channels.c1.type = memory

指定攔截器
指定攔截器的別名
a1.sources.r1.interceptors = i1

指定攔截期的類型
a1.sources.r1.interceptors.i1.type = host

綁定agent的  r1   c1   k1 
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1




數據:
Event: { headers:{host=192.168.191.203} body: 68 65 6C 6C 6F 20 74 6F 6D 0D hello tom. }
使用:
%{host}

3)Static Interceptor

​ 靜態攔截器 攔截每一個event數據 手動定義攔截器的key value 手動在header中添加 需要添加的k v 便於後面的數據的分類使用
案例:

指定當前agent a1的 sources sinks  channels 的別名
a1.sources = r1
a1.sinks = k1
a1.channels = c1

agent的數據源的
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

定義攔截器
定義攔截器的別名
a1.sources.r1.interceptors = i1

定義攔截器的類型的
a1.sources.r1.interceptors.i1.type = static

手動指定攔截器的 key值
a1.sources.r1.interceptors.i1.key = class

手動指定攔截器的value值
a1.sources.r1.interceptors.i1.value = two

指定agent的sink的
a1.sinks.k1.type = logger

指定agent的通道
a1.channels.c1.type = memory

綁定agent的  r1   c1   k1 
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1




headers:{class=bd1811}

4)多個攔截器聯合使用:

指定當前agent a1的 sources sinks  channels 的別名

a1.sources = r1
a1.sinks = k1
a1.channels = c1

agent的數據源的

a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

定義攔截器

定義攔截器的別名

a1.sources.r1.interceptors = i1 i2

i1定義攔截器的類型的

a1.sources.r1.interceptors.i1.type = static

i1手動指定攔截器的 key值

a1.sources.r1.interceptors.i1.key = class

i1手動指定攔截器的value值

a1.sources.r1.interceptors.i1.value = bd1811

指定i2對應的攔截器

a1.sources.r1.interceptors.i2.type = timestamp

指定agent的sink的

a1.sinks.k1.type = logger

指定agent的通道

a1.channels.c1.type = memory

綁定agent的  r1   c1   k1 

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1




自定義攔截器

請見下文

自定義flume攔截器-實現了多種功能

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章