|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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」