使用更改后的TaildirSource,可以递归地监听配置目录的动态变化的文件。
需求描述
使用了SpoolDirectorySource
可以配置一个监听目录,会监听该目录下所有的文件,但是如果配置目录下面嵌套了子目录,则无法监听,通过修改源码,我们可以递归地对配置目录的所有子目录的所有文件进行监听,见上一篇文章 Flume的Spooling Directory Source支持Sub-directories
但是,SpoolDirectorySource
的一个限制还没有消除,即监听目录下的文件不允许动态变化。比如我在收集yarn的nodemanager的日志时候,发现监听目录下面的文件是动态追加的,而不是先生成一个.tmp
临时文件,全部写完后rename
,这样,我们还需要对SpoolDirectorySource
进行改进:可以对动态追加内容的文件进行实时监听。
这有点像:ExecSource
+ SpoolDirectorySource
的一个source
解决方案
先看看能否踩在巨人的肩膀上,查看flume1.7.0
的 realease note
,发现增加了一个Taildir Source
,点进去发现,这不就是我们需要的吗!
我贴一下官方的description:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
好,有了它,下面就有两种解决方案:
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
的配置:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
类似SpoolDirectorySource
增加该feature所做的工作,我们最后还需要给TaildirSource
增加该feature以满足我们的需求。
改动类似《Flume的Spooling Directory Source支持Sub-directories》所涉及到,需要注意的是,
filegroups
可以指定多个监听源,每个源指定相应的监听路径下面的哪些文件,这里的下面经过改动后会递归地包含下面的所有子目录。
比如:
配置了/home/urey/yarn_log/.*
,会监听:
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
最新的代码我已上传到github上,欢迎试用:
flume-source-taildir-recursive
注:
由于flume1.7.0本身还没有发布,所以TaildirSource
可能存在缺陷,如果遇到问题,需要通过查看日志定位问题,看社区是否有相应的issue和解决方案。