关于flume里面两种source的区别,以及操作的时候报相关的错误。

Exec Source
        可以将命令产生的输出作为源

        属性说明:
            !channels    –     
            !type    –    类型名称,需要是"exec"
            !command    –    要执行的命令
            shell    –    A shell invocation used to run the command. e.g. /bin/sh -c. Required only for commands relying on shell features like wildcards, back ticks, pipes etc.
            restartThrottle    10000    毫秒为单位的时间,用来声明等待多久后尝试重试命令
            restart    false    如果cmd挂了,是否重启cmd
            logStdErr    false    无论是否是标准错误都该被记录
            batchSize    20    同时发送到通道中的最大行数
            batchTimeout    3000    如果缓冲区没有满,经过多长时间发送数据
            selector.type    复制还是多路复用
            selector.*         Depends on the selector.type value
            interceptors    –    空格分隔的拦截器列表
            interceptors.*          
        案例:
            编写配置文件:
                #命名Agent a1的组件
                a1.sources  =  r1
                a1.sinks  =  k1
                a1.channels  =  c1

                #描述/配置Source
                a1.sources.r1.type  =  avro
                a1.sources.r1.bind  =  0.0.0.0
                a1.sources.r1.port  =  33333

                #描述Sink
                a1.sinks.k1.type  =  logger
                #描述内存Channel
                a1.channels.c1.type  =  memory
                a1.channels.c1.capacity  =  1000
                a1.channels.c1.transactionCapacity  =  100

                #为Channle绑定Source和Sink
                a1.sources.r1.channels  =  c1
                a1.sinks.k1.channel  =  c1

            启动flume:
                ./flume-ng agent --conf ../conf --conf-file ../conf/template2.conf --name a1 -Dflume.root.logger=INFO,console

            **可以通过tail命令,收集日志文件中后续追加的日志

!!!3.Spooling Directory Source    
        这个Source允许你将文件将要收集的数据放置到"自动搜集"目录中。这个Source将监视该目录,并将解析新文件的出现。事件处理逻辑是可插拔的,当一个文件被完全读入信道,它会被重命名或可选的直接删除。 要注意的是,放置到自动搜集目录下的文件不能修改,如果修改,则flume会报错。另外,也不能产生重名的文件,如果有重名的文件被放置进来,则flume会报错。


        属性说明:
            !channels    –     
            !type    –    类型,需要指定为"spooldir"
            !spoolDir    –    读取文件的路径,即"搜集目录"
            fileSuffix    .COMPLETED    对处理完成的文件追加的后缀
            deletePolicy    never    处理完成后是否删除文件,需是"never"或"immediate"
            fileHeader    false    Whether to add a header storing the absolute path filename.
            fileHeaderKey    file    Header key to use when appending absolute path filename to event header.
            basenameHeader    false    Whether to add a header storing the basename of the file.
            basenameHeaderKey    basename    Header Key to use when appending basename of file to event header.
            ignorePattern    ^$    正则表达式指定哪些文件需要忽略
            trackerDir    .flumespool    Directory to store metadata related to processing of files. If this path is not an absolute path, then it is interpreted as relative to the spoolDir.
            consumeOrder    处理文件的策略,oldest, youngest 或 random。
            maxBackoff    4000    The maximum time (in millis) to wait between consecutive attempts to write to the channel(s) if the channel is full. The source will start at a low backoff and increase it exponentially each time the channel throws a ChannelException, upto the value specified by this parameter.
            batchSize    100    Granularity at which to batch transfer to the channel
            inputCharset    UTF-8    读取文件时使用的编码。
            decodeErrorPolicy    FAIL    当在输入文件中发现无法处理的字符编码时如何处理。FAIL:抛出一个异常而无法 ​​解析该文件。REPLACE:用“替换字符”字符,通常是Unicode的U + FFFD更换不可解析角色。 忽略:掉落的不可解析的字符序列。
            deserializer    LINE    声明用来将文件解析为事件的解析器。默认一行为一个事件。处理类必须实现EventDeserializer.Builder接口。
            deserializer.*         Varies per event deserializer.
            bufferMaxLines    –    (Obselete) This option is now ignored.
            bufferMaxLineLength    5000    (Deprecated) Maximum length of a line in the commit buffer. Use deserializer.maxLineLength instead.
            selector.type    replicating    replicating or multiplexing
            selector.*         Depends on the selector.type value
            interceptors    –    Space-separated list of interceptors
            interceptors.*          

        案例:
            编写配置文件:
                #命名Agent a1的组件
                a1.sources  =  r1
                a1.sinks  =  k1
                a1.channels  =  c1

                #描述/配置Source
                a1.sources.r1.type  = spooldir
                a1.sources.r1.spoolDir  = /home/park/work/apache-flume-1.6.0-bin/mydata

                #描述Sink
                a1.sinks.k1.type  =  logger
                #描述内存Channel
                a1.channels.c1.type  =  memory
                a1.channels.c1.capacity  =  1000
                a1.channels.c1.transactionCapacity  =  100

                #为Channle绑定Source和Sink
                a1.sources.r1.channels  =  c1
                a1.sinks.k1.channel  =  c1


            启动flume:
                ./flume-ng agent --conf ../conf --conf-file ../conf/template4.conf --name a1 -Dflume.root.logger=INFO,console

            向指定目录中传输文件,发现flume收集到了该文件,将文件中的每一行都作为日志来处理。

关于这两种的配置,我在进行tomcat的日志采集的时候发现了错误。如果利用exec source的话,我就用tail -F tomcat/log/xxxx.log。{

tail -f      等同于--follow=descriptor,根据文件描述符进行追踪,当文件改名或被删除,追踪停止

tail -F     等同于--follow=name  --retry,根据文件名进行追踪,并保持重试,即该文件被删除或改名后,如果再次创建相同的文件名,会继续追踪

}利用tail命令来追踪tomcat的产生的日志。

或者利用spooling dir来检测目录下面产生的文件。当目录下面的某个文件读入到channel之后,就不能再对该文件执行进行修改了。否则会报错的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值