168大数据

标题: HDFS Sink使用技巧 [打印本页]

作者: 168主编    时间: 2019-10-25 10:59
标题: HDFS Sink使用技巧
1、文件滚动策略
在HDFS Sink的文件滚动就是文件生成,即关闭当前文件,创建新文件。它的滚动策略由以下几个属性控制:
hdfs.rollInterval
基于时间间隔来进行文件滚动,默认是30,即每隔30秒滚动一个文件。0就是不使用这个策略。
hdfs.rollSize
基于文件大小进行文件滚动,默认是1024,即当文件大于1024个字节时,关闭当前文件,创建新的文件。0就是不使用这个策略。
hdfs.rollCount
基于event数量进行文件滚动。默认是10,即event个数达到10时进行文件滚动。0就是不使用这个策略。
hdfs.idleTimeout
闲置N秒后,关闭当前文件(去掉.tmp后缀)。
以上这些策略可以同时启用,比如下面的配置的策略是:每大约50K一个文件,闲置10秒则关闭当前文件(.tmp)
[AppleScript] 纯文本查看 复制代码
a1.sinks=k1
...
a1.sinks.k1.type=hdfs
a1.sinks.k1.hdfs.path=hdfs​://vm1:8020/flume/
a1.sinks.k1.hdfs.rollInterval=0
a1.sinks.k1.hdfs.rollSize=50000
a1.sinks.k1.hdfs.rollCount=0
a1.sinks.k1.hdfs.idleTimeout=10

2、文件名策略
文件路径或文件名可以使用占位符,官方提供的占位符如下:​
AliasDescription
%{host}
Substitute value of event header named “host”. Arbitrary header names are supported.
%t
Unix time in milliseconds
%a
locale’s short weekday name (Mon, Tue, ...)
%A
locale’s full weekday name (Monday, Tuesday, ...)
%b
locale’s short month name (Jan, Feb, ...)
%B
locale’s long month name (January, February, ...)
%c
locale’s date and time (Thu Mar 3 23:05:25 2005)
%d
day of month (01)
%D
date; same as %m/%d/%y
%H
hour (00..23)
%I
hour (01..12)
%j
day of year (001..366)
%k
hour ( 0..23)
%m
month (01..12)
%M
minute (00..59)
%p
locale’s equivalent of am or pm
%s
seconds since 1970-01-01 00:00:00 UTC
%S
second (00..59)
%y
last two digits of year (00..99)
%Y
year (2010)
%z
+hhmm numeric timezone (for example, -0400)

想要使用跟时间、日期有关的占位符,需要有timestamp拦截器
想要使用host属性,需要有host拦截器
如果有自定义拦截器,也可以使用自定义属性。
1)文件的命名
hdfs.filePrefix 文件前缀,默认是FlumeData
hdfs.fileSuffix 文件后缀,默认没有。
例子如下,文件以分钟命名:
[AppleScript] 纯文本查看 复制代码
a1.sinks=k1
...
a1.sinks.k1.type=hdfs
...
a1.sinks.k1.hdfs.filePrefix=%M.log
2)文件父路径的命名:
例子如下,/host地址/年-月-日/:
[AppleScript] 纯文本查看 复制代码
a1.sinks=k1
...
a1.sinks.k1.type=hdfs
...
a1.sinks.k1.hdfs.path=hdfs://vm1:8020/flume/%{host}/%Y-%m-%d

来自为知笔记(Wiz)





欢迎光临 168大数据 (http://www.bi168.cn/) Powered by Discuz! X3.2