flume-TailDirSource分析

本文详细分析了Flume的TailDirSource组件,包括其参数解析、内部结构和核心方法。TailDirSource监控指定目录,根据正则表达式筛选文件,可配置是否从文件末尾开始读取及递归子目录。它使用DirWatcher线程来检测目录变化,当文件创建或删除时,触发相应处理。DirWatcher的核心方法check()负责检查目录更新,并触发事件。
摘要由CSDN通过智能技术生成

TailDirSource
tailDir("dirname"[, fileregex=".*"[, startFromEnd=false[, recurseDepth=0]]]{,delim="regex", delimMode="exclude|prev|next"})  :: Tails all files in a directory   dirname  that match the specified   fileregex. Be careful and make sure because the regex argument requires java style escaping of   \  and   \". For example   \w+  would have to be written as "\\w+". If a new file appears, it is added to the list of files to tail. If pointed at a new directory, it will attempt to read all files that match! If the   startFromEnd  parameter is false, tail will re-read from the beginning of each file. If it is true, it will only start reading from the current end of each file. If the   recurseDepth  parameter is > 0 then tailDir will recurse into sub-directories. The value defines max level of a directory below the   dirname  to tail files in. Zero means do not recurse into sub-directories. Note: fileregex is applied to file names only (not including dirs), all directories (which fit   recurseDepth  parameter) are recursed into. See the section on tailing a file for details on   delim  and   delimMode
上面是用户指南对TailDir的用法解释。与之对应的源代码是
public EventSource build(Context ctx, String... argv) {
        Preconditions
            . checkArgument(argv.length >= 1 && argv. length <= 4, USAGE);
        String regex = ".*"; // default to accepting all
        if (argv.length >= 2) {
          regex = argv[1];
        }
        boolean startFromEnd = false;
        if (argv.length >= 3) {
          startFromEnd = Boolean.parseBoolean(argv[2]);
        }
        int recurseDepth = 0;
        if (argv.length >= 4) {
          recurseDepth = Integer. parseInt(argv[3]);
          Preconditions. checkArgument(recurseDepth >= 0,
              "\"recurseDepth\" should be >= 0, but was: " + recurseDepth
                  + ".\n" + USAGE );
        }
        // delim regex, delim mode
        Pair<String, DelimMode> mode = TailSource. extractDelimContext(ctx);
        if (mode != null) {
          return new TailDirSource(new File(argv[0]), regex, startFromEnd,
              recurseDepth, mode.getLeft(), mode.getRight());
        }
        return new TailDirSource(new File(argv[0]), regex, startFromEnd,
            recurseDepth);
  }

    


它一共需要四个参数,用监控的目录,对监控目录中文件的过滤正则,是否要从文件开始收取默认是从头开始,递归监控目录的层次默认为不递归;接下来
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值