1.概述
Flume有能力在運行階段修改/刪除Event,這是通過攔截器(Interceptors)來實現的。
攔截器需要實現org.apache.flume.interceptor.Interceptor接口。
攔截器可以修改或刪除事件基於開發者在選擇器中選擇的任何條件。
攔截器采用了責任鏈模式,多個攔截器可以按指定順序攔截。
一個攔截器返回的事件列表被傳遞給鏈中的下一個攔截器。
如果一個攔截器需要刪除事件,它只需要在返回的事件集中不包含要刪除的事件即可。
如果要刪除所有事件,只需返回一個空列表。
2.Timestamp Interceptor
這個攔截器在事件頭中插入以毫秒為單位的當前處理時間。
頭的名字為timestamp,值為當前處理的時間戳。
如果在之前已經有這個時間戳,則保留原有的時間戳。
參數說明:
!type – 類型名稱,必須是timestamp或自定義類的全路徑名
preserveExisting false 如果時間戳已經存在是否保留
3.Host Interceptor
這個攔截器插入當前處理Agent的主機名或ip
頭的名字為host或配置的名稱
值是主機名或ip地址,基於配置。
參數說明:
!type – 類型名稱,必須是host
preserveExisting false 如果主機名已經存在是否保留
useIP true 如果配置為true則用IP,配置為false則用主機名
hostHeader host 加入頭時使用的名稱
4.Static Interceptor
此攔截器允許用戶增加靜態頭信息使用靜態的值到所有事件。
目前的實現中不允許一次指定多個頭。
如果需要增加多個靜態頭可以指定多個Static interceptors
屬性說明:
!type – 類型,必須是static
preserveExisting true 如果配置頭已經存在是否應該保留
key key 要增加的透明
value value 要增加的頭值
5.UUID Interceptor
這個攔截器在所有事件頭中增加一個全局一致性標志。
其實就是UUID。
屬性說明:
!type – 類型名稱,必須是org.apache.flume.sink.solr.morphline.UUIDInterceptor$Builder
headerName id 頭名稱
preserveExisting true 如果頭已經存在,是否保留
prefix “” 在UUID前拼接的字符串前綴
6.Morphline Interceptor
7.Search and Replace Interceptor
這個攔截器提供了簡單的基於字符串的正則搜索和替換功能。
屬性說明:
type – 類型名稱,必須是"search_replace"
searchPattern – 要搜索和替換的正則表達式
replaceString – 要替換為的字符串
charset UTF-8 字符集編碼,默認utf-8
8.Regex Filtering Interceptor
此攔截器通過解析事件體去匹配給定正則表達式來篩選事件。
所提供的正則表達式即可以用來包含或刨除事件。
屬性說明:
!type – 類型,必須設定為regex_filter
regex ”.*” 所要匹配的正則表達式
excludeEvents false 如果是true則刨除匹配的事件,false則包含匹配的事件。
9.Regex Extractor Interceptor
使用指定正則表達式匹配事件,並將匹配到的組作為頭加入到事件中。
它也支持插件化的序列化器用來格式化匹配到的組在加入他們作為頭之前。
屬性說明:
!type – 類型,必須是regex_extractor
!regex – 要匹配的正則表達式
!serializers – Space-separated list of serializers for mapping matches to header names and serializing their values. (See example below) Flume provides built-in support for the following serializers: org.apache.flume.interceptor.RegexExtractorInterceptorPassThroughSerializer org.apache.flume.interceptor.RegexExtractorInterceptorMillisSerializer
serializers.<s1>.type default Must be default (org.apache.flume.interceptor.RegexExtractorInterceptorPassThroughSerializer), org.apache.flume.interceptor.RegexExtractorInterceptorMillisSerializer, or the FQCN of a custom class that implements org.apache.flume.interceptor.RegexExtractorInterceptorSerializer
serializers.<s1>.name –
serializers.* – Serializer-specific properties
----
If the Flume event body contained 1:2:3.4foobar5 and the following configuration was used
a1.sources.r1.interceptors.i1.regex = (\\d):(\\d):(\\d)
a1.sources.r1.interceptors.i1.serializers = s1 s2 s3
a1.sources.r1.interceptors.i1.serializers.s1.name = one
a1.sources.r1.interceptors.i1.serializers.s2.name = two
a1.sources.r1.interceptors.i1.serializers.s3.name = three
The extracted event will contain the same body but the following headers will have been added one=>1, two=>2, three=>3
----