|NO.Z.00047|——————————|BigDataEnd|——|Hadoop&Flume.V10|——|Flume.v10|高级特性|拦截器|高可用|选择器.v02|

一、Host添加拦截器
### --- Host添加拦截器

~~~     这个拦截器会把当前Agent的 hostname 或者 IP 地址写入到Event的header中,
~~~     key默认是“host”(也可以通过配置自定义key),value可以选择使用hostname或者IP地址。
二、host添加拦截器测试:
### --- 在时间拦截器案例的基础上,在配置文件中增加主机名拦截器的配置。命名为hostname.conf

[root@linux123 ~]# vim $FLUME_HOME/conf/hostname.conf

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = linux123
a1.sources.r1.port = 8888

# 这部分是新增 时间拦截器 的内容
a1.sources.r1.interceptors = i1 i2
a1.sources.r1.interceptors.i1.type = timestamp
a1.sources.r1.interceptors.i1.preserveExisting= false

# 这部分是新增 时间拦截器 的内容
# 这部分是新增 主机名拦截器 的内容
a1.sources.r1.interceptors.i2.type = host

# 如果header中已经存在同名的属性是否保留
a1.sources.r1.interceptors.i2.preserveExisting= false

# true:使用IP地址;false:使用hostname
a1.sources.r1.interceptors.i2.useIP = false

# 这部分是新增 主机名拦截器 的内容
# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 10000
a1.channels.c1.transactionCapacity = 500

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
### --- 启动Agent,启动 telnet 输入信息
~~~     可以看见event headers  增加了主机名信息、时间戳信息。

[root@linux123 ~]#  $FLUME_HOME/bin/flume-ng agent --name a1 \
--conf-file $FLUME_HOME/conf/hostname.conf \
-Dflume.root.logger=INFO,console
~~输出参数
INFO sink.LoggerSink: Event: { headers:{host=linux123, timestamp=1630137142812} body: 68 65 6C 6C 6F 20 77 6F 72 6C 64 0D             hello world. }
INFO sink.LoggerSink: Event: { headers:{host=linux123, timestamp=1630137143874} body: 31 0D                                           1. }
INFO sink.LoggerSink: Event: { headers:{host=linux123, timestamp=1630137144279} body: 32 0D                                           2. }
INFO sink.LoggerSink: Event: { headers:{host=linux123, timestamp=1630137144671} body: 33 0D                                           3. }
INFO sink.LoggerSink: Event: { headers:{host=linux123, timestamp=1630137145067} body: 34 0D                                           4. }
INFO sink.LoggerSink: Event: { headers:{host=linux123, timestamp=1630137145572} body: 35 0D                                           5. }

[root@linux123 ~]# telnet linux123 8888
# 输入 hello world
### --- 正则表达式过滤拦截器

~~~     这个拦截器会把Event的body当做字符串来处理,并用配置的正则表达式来匹配。
~~~     可以配置指定被匹配到的Event丢弃还是没被匹配到的Event丢弃。

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(14)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示