Flume抽取数据(包含自定义拦截器和时间戳拦截器)

flume参考网址:Flume 1.9用户手册中文版 --- 可能是目前翻译最完整的版本了https://flume.liyifeng.org/?flag=fromDoc#要求:

使用Flume将日志抽取到hdfs上:通过java代码编写一个拦截器,将日志中不是json数据的数据过滤掉,只保留符合json格式的数据,抽出到hdfs中的数据要有日期路径

日志数据:

最终到hdfs上的数据格式:

步骤:

①首先确保hdfs的服务是开启的

bash 复制代码
start-dfs.sh

②将使用java写好的jar包导入到flume的lib下

③编写json文件

#为各组件命名

a1.sources = r1

a1.channels = c1

a1.sinks = k1

#描述source

a1.sources.r1.type = TAILDIR

a1.sources.r1.filegroups = f1

a1.sources.r1.filegroups.f1 = /home/behavior/.*

a1.sources.r1.positionFile = /root/taildir_position.json

a1.sources.r1.interceptors = i1

a1.sources.r1.interceptors.i1.type = cn.wolfcode.flume.interceptor.ETLInterceptor$Builder

a1.sources.r1.interceptors = i2

a1.sources.r1.interceptors.i2.type = cn.wolfcode.flume.interceptor.TimeStampInterceptor$Builder

channel1

a1.channels.c1.type = memory

a1.channels.c1.capacity = 1000

a1.channels.c1.transactionCapacity = 100

sink1

a1.sinks.k1.type = hdfs

a1.sinks.k1.hdfs.path = /behavior/origin/log/%Y-%m-%d

a1.sinks.k1.hdfs.filePrefix = log-

a1.sinks.k1.hdfs.round = false

a1.sinks.k1.hdfs.rollInterval = 10

a1.sinks.k1.hdfs.rollSize = 134217728

a1.sinks.k1.hdfs.rollCount = 0

控制输出文件是原生文件。

a1.sinks.k1.hdfs.fileType = DataStream

a1.sinks.k1.hdfs.writeFormat= Text

拼装

a1.sources.r1.channels = c1

a1.sinks.k1.channel= c1

抽取:

bash 复制代码
flume-ng agent -n a1 -c ../ -f taildir2hdfs.conf -Dflume.root.logger=INFO,console

关于时间戳拦截器:

假如hdfs中使用了时间转义字符,此时必须指定时间,两种方案

(1)使用本地时间戳

a1.sinks.k1.hdfs.useLocalTimeStamp =true

(2)使用时间拦截器

a1.sources.r1.interceptors = i1

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

相关推荐
一名普通的电源工程师4 小时前
E0512XT-1WR3 适配优选 钡特电源 DF1-05D12XT|1W 隔离5V转±12V模块电源选型参数技术解析
大数据·网络·人工智能
SelectDB4 小时前
Apache Doris 2026 Roadmap:AI 时代数据基础设施如何选型?Doris 给出了三层架构答案
大数据
Think_Higher5 小时前
CID行业趋势周报|7.27—8.02:大盘表现、重点赛道与投测建议
大数据·人工智能
林澈在路上5 小时前
2026 主流 AI 写歌 APP 全面测评|零基础原创歌曲工具选购指南
大数据·人工智能·aigc·音视频·音频
2501_946736166 小时前
在线考试平台如何选型?从功能、优势与应用场景角度详解
大数据·人工智能·算法
字节跳动数据平台6 小时前
文件上传即可检索|实时多模态向量链路落地实践分享
大数据
一个数据大开发7 小时前
Skill、Tool、SOP、MCP 文章合集
大数据·人工智能·知识图谱
大大大大晴天️7 小时前
浅析StarRocks 表设计:表类型、分布策略与索引
大数据·starrocks
weixin_397574098 小时前
按行业定制分析视角
大数据·数据库·人工智能·企业数据治理·数据驱动决策·本体语义·企业经营分析
阴雨天xiiii8 小时前
德国慕尼黑国际太阳能展特装展台施工落地方案拆解
大数据·网络