flume 高级组件篇

前言

记录 在学习大数据技术过程中的学习笔记

目录

高级组件

Event

Source Interceptors 拦截器

案例一:对采集到的数据按天按类型分目录存储

Channel Selectors 选择器

案例二:多Channel之Replicating Channel Selector

案例三:多Channel HDFS 和 Kafka

案例四:多Channel之Multiplexing Channel Selector

Sink Processors 

flume 各种自定义组件

Flume优化

调整Flume内存大小

配置多个日志文件

Flume进程监控


高级组件

Source Interceptors:Source可以指定一个或者多个拦截器按先后顺序依次采集到的数据进行处理

Channel Selectors:Source发往多个Channel的策略设置

Sink Processors:Sink发送数据的策略设置

Event

Event是Flume是传输数据的基本单位,也是事务的基本单位,在文本文件中,通常一行记录就是一个Event

Event里有header和body;header类型为Map<String,String>

我们可以在Source中增加header的<key,value>,在Channel和Sink中使用header中的值

Source Interceptors 拦截器

常见的Interceptors类型:

Timestamp Interceptor(时间戳拦截器) 主要用于往Event的header里面添加timestamp时间戳信息的、

Host Interceptor 主要用于向Event中的header里面去添加host属性,这个属性的值一般就是当前机器的一个主机名或者IP信息、

Search and Replace Interceptor 根据指定的规则查询Event中的body里面的那个原始数据,然后根据这个规则进行替换,它会修改Event中body中的值,也就是说它会修改你采集到的原始数据、 

Static Interceptor  静态的,它可以固定的往Event的header里面添加一些key和value、

Regex Extractor Interceptor 根据指定的规则从Event的body里面去抽取数据 ,然后生成key和value,在把key和value添加到Event的header里面

案例一:对采集到的数据按天按类型分目录存储

Exec Source -> Search and Replace Interceptor -> Regx Extractor

Interceptor -> File Channel -> HDFS Sink

在第四台机器上创建文件

vi file-to-hdfs-more.conf
# agent的名称是a1
# 指定source组件、channel组件和Sink组件的名称
a1.sources = r1
a1.channels = c1
a1.sinks = k1

# 配置source组件
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /data/log/moreType.log

# 配置拦截器 [多个拦截器按照顺序依次执行]
a1.sources.r1.interceptors = i1 i2 i3 i4
#拦截器类型
a1.sources.r1.interceptors.i1.type = search_replace
#根据正则匹配
a1.sources.r1.interceptors.i1.searchPattern = "type":"video_info"
#匹配到后替换成
a1.sources.r1.interceptors.i1.replaceString = "type":"videoInfo"

#拦截器类型
a1.sources.r1.interceptors.i2.type = search_replace
#根据正则匹配
a1.sources.r1.interceptors.i2.searchPattern = "type":"user_info"
#匹配到后替换成
a1.sources.r1.interceptors.i2.replaceString = "type":"userInfo"

a1.sources.r1.interceptors.i3.type = search_replace
a1.sources.r1.interceptors.i3.searchPattern = "type":"gift_record"
a1.sources.r1.interceptors.i3.replaceString = "type":"giftRecord"

# 正则抽取拦截器
a1.sources.r1.interceptors.i4.type = regex_extractor
# 正则匹配到的内容会被抽取出来
a1.sources.r1.interceptors.i4.regex = "type":"(\\w+)"
# 定义变量s1 值为 抽取的内容
a1.sources.r1.interceptors.i4.serializers = s1
# 在header里面生成键值(<logType,s1>)
a1.sources.r1.interceptors.i4.serializers.s1.name = logType


# 配置channel组件
a1.channels.c1.type = file
a1.channels.c1.checkpointDir = /data/soft/apache-flume-1.9.0-bin/data/moreType/checkpoint
a1.channels.c1.dataDirs = /data/soft/apache-flume-1.9.0-bin/data/moreType/data


# 配置sink组件
a1.sinks.k1.type = hdfs
#这里的logType就是上面拦截器生成的
a1.sinks.k1.hdfs.path = hdfs://192.168.10.100:9000/moreType/%Y%m%d/%{logType}
a1.sinks.k1.hdfs.fileType = DataStream
a1.sinks.k1.hdfs.writeFormat = Text
a1.sinks.k1.hdfs.rollInterval = 3600
a1.sinks.k1.hdfs.rollSize = 134217728
a1.sinks.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值