Flume1.7.0的TaildirSource介绍

使用更改后的TaildirSource,可以递归地监听配置目录的动态变化的文件。


需求描述

使用了SpoolDirectorySource可以配置一个监听目录,会监听该目录下所有的文件,但是如果配置目录下面嵌套了子目录,则无法监听,通过修改源码,我们可以递归地对配置目录的所有子目录的所有文件进行监听,见上一篇文章 Flume的Spooling Directory Source支持Sub-directories

但是,SpoolDirectorySource的一个限制还没有消除,即监听目录下的文件不允许动态变化。比如我在收集yarn的nodemanager的日志时候,发现监听目录下面的文件是动态追加的,而不是先生成一个.tmp临时文件,全部写完后rename,这样,我们还需要对SpoolDirectorySource进行改进:可以对动态追加内容的文件进行实时监听。

这有点像:ExecSource + SpoolDirectorySource 的一个source


解决方案

先看看能否踩在巨人的肩膀上,查看flume1.7.0realease note ,发现增加了一个Taildir Source,点进去发现,这不就是我们需要的吗!

我贴一下官方的description:

Description
This is the proposal of implementing a new tailing source.
This source watches the specified files, and tails them in nearly real-time once appends are detected to these files.
This source is reliable and will not miss data even when the tailing files rotate.
It periodically writes the last read position of each file in a position file using the JSON format.
If Flume is stopped or down for some reason, it can restart tailing from the position written on the existing position file.
It can add event headers to each tailing file group.
A attached patch includes a config documentation of this.
This source requires Unix-style file system and Java 1.7 or later.

好,有了它,下面就有两种解决方案:
1. 直接使用flume1.7.0
2. 将该feature增加到flume1.6.0中

由于我们已经对flume1.6.0做了比较大的改动,所以显然需要第二种方案。

集成过程中主要改动的是两个module
1. 将flume-taildir-source添加到flume-ng-sources
2. 编译根据提示一步一步修改flume-ng-core下的部分文件


增加递归监听子目录的特性

贴一下TaildirSource的配置:

    # source2: tail_dir_source -----------------
    agent.sources.tail_dir_source.type = org.apache.flume.source.taildir.TaildirSource
    agent.sources.tail_dir_source.channels = memory_channel
    agent.sources.tail_dir_source.positionFile = /tmp/taildir_position.json
    agent.sources.tail_dir_source.filegroups = f1
    agent.sources.tail_dir_source.filegroups.f1 = /home/urey/yarn_log/.*
    agent.sources.tail_dir_source.batchSize = 100
    agent.sources.tail_dir_source.backoffSleepIncrement  = 1000
    agent.sources.tail_dir_source.maxBackoffSleep  = 5000
    agent.sources.tail_dir_source.recursiveDirectorySearch = true
    agent.sources.tail_dir_source.yarnApplicationHeader = true
    agent.sources.tail_dir_source.yarnContainerHeader = true

类似SpoolDirectorySource增加该feature所做的工作,我们最后还需要给TaildirSource增加该feature以满足我们的需求。

改动类似《Flume的Spooling Directory Source支持Sub-directories》所涉及到,需要注意的是,
filegroups可以指定多个监听源,每个源指定相应的监听路径下面的哪些文件,这里的下面经过改动后会递归地包含下面的所有子目录。

比如:
配置了/home/urey/yarn_log/.*,会监听:

/home/urey/yarn_log/test1.log
/home/urey/yarn_log/dir1/test2.log
/home/urey/yarn_log/dir1/dir2/test3.log
...
等等

最新的代码我已上传到github上,欢迎试用:

flume-source-taildir-recursive

注:
由于flume1.7.0本身还没有发布,所以TaildirSource可能存在缺陷,如果遇到问题,需要通过查看日志定位问题,看社区是否有相应的issue和解决方案。

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值