zoukankan      html  css  js  c++  java
  • 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)

    1
    2
    3
    4
    5
    6
    7
    8
    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.
    %tUnix time in milliseconds
    %alocale’s short weekday name (Mon, Tue, ...)
    %Alocale’s full weekday name (Monday, Tuesday, ...)
    %blocale’s short month name (Jan, Feb, ...)
    %Blocale’s long month name (January, February, ...)
    %clocale’s date and time (Thu Mar 3 23:05:25 2005)
    %dday of month (01)
    %Ddate; same as %m/%d/%y
    %Hhour (00..23)
    %Ihour (01..12)
    %jday of year (001..366)
    %khour ( 0..23)
    %mmonth (01..12)
    %Mminute (00..59)
    %plocale’s equivalent of am or pm
    %sseconds since 1970-01-01 00:00:00 UTC
    %Ssecond (00..59)
    %ylast two digits of year (00..99)
    %Yyear (2010)
    %z+hhmm numeric timezone (for example, -0400)

    想要使用跟时间、日期有关的占位符,需要有timestamp拦截器

    想要使用host属性,需要有host拦截器

    如果有自定义拦截器,也可以使用自定义属性。

    1)文件的命名

    hdfs.filePrefix 文件前缀,默认是FlumeData

    hdfs.fileSuffix 文件后缀,默认没有。

    例子如下,文件以分钟命名:

    1
    2
    3
    4
    5
    a1.sinks=k1
    ...
    a1.sinks.k1.type=hdfs
    ...
    a1.sinks.k1.hdfs.filePrefix=%M.log

    2)文件父路径的命名:

    例子如下,/host地址/年-月-日/:

    1
    2
    3
    4
    5
    a1.sinks=k1
    ...
    a1.sinks.k1.type=hdfs
    ...
    a1.sinks.k1.hdfs.path=hdfs://vm1:8020/flume/%{host}/%Y-%m-%d









  • 相关阅读:
    本周学习进度条11
    编程珠玑阅读笔记01
    单词统计
    本周学习进度条10
    《构建之法》读后感三
    第九周总结
    第一阶段冲刺
    第八周总结
    wpf图片浏览器,实现缩放平移操作图片切换等功能
    获取当前进程(程序)主窗体句柄并设置wpf的父窗体为此句柄
  • 原文地址:https://www.cnblogs.com/lishouguang/p/4560898.html
Copyright © 2011-2022 走看看