Flume-ng日志收集简介

初来乍到,第一篇博文,错误支持多多包含多多指点微笑


以下内容以Flume 1.5.2版本为基础(反正1.x都差不多)大笑看完此文,就相当于看完了官方文档。


数据流模型

eventFlume数据流的基本数据单元,包含header(一组string属性)和body(二进制数组)两部分。

agent:一个Flumeagent是一个JVM进程,有sourcechannelsink三大组件构成。

source:接收agent外部发送来的events,并存储到一个channel或多个channels

channelevents的临时存储管道。

sink:将events发送到数据存储目的地或下一个agentsource



复杂的流组合

多个agents可以连接在一起,形成复杂的数据流,支持fan-infan-out

Reliability

是指events保存在channel中,只有被sink消费之后,才会从channel中删除。

Recoverability

是指Flume支持类似file的持久化channel

备注:

官方文档对Flume可靠性和可恢复性的解释,只是表示针对channel中的数据而言。


安装Flume插件

Flume拥有一个完整的基于插件的架构设计。

1)将自定义组件的jars添加到flume-env.sh文件的FLUME_CLASSPATH变量中。

2)插件部署在$FLUME_HOME/plugins.d目录下,每一个插件在plugins.d目录中创建一个插件子目录,每一个插件子目录可以拥有以下三个子目录:

 lib – 插件jar(s)

 libext – 插件依赖jar(s)

 native - any required native libraries,such as .so files

设置多agent

在多个agent之间传输数据,将前一个agentsink连接到下一个agentsource

数据合并(fan-in

多路传输(fan-out

This fan out can be replicating(default) ormultiplexing

replicating:每一个event都被发送到source对应的所有channels

multiplexing:根据每一个eventheader,将其发送到预先配置的一个channel或多个channels

a1.sources=r1

a1.channels=c1 c2 c3 c4

a1.sources.r1.selector.type=multiplexing

a1.sources.r1.selector.header=state

a1.sources.r1.selector.mapping.CZ=c1

a1.sources.r1.selector.mapping.US=c2 c3

a1.sources.r1.selector.default=c4

Flume sources

  • Avro Source

  • Thrift Source

  • Exec Source

    执行cat[named pipe]or tail-F[file]之类的命令,将命令输出到stdout的数据发送到channel

    和其他异步发送一样,如果不能把数据发送到channelclient(应用程序)无法获得通知,数据丢失。

    如果exec执行的commandexists,该source也会exists,不再生产数据到channel

    不可靠。

  • JMS Source

    JMS消息队列中获取数据。

  • Spooling Directory Source

    source监控指定目录,如果有新的文件出现,就会把新文件解析为events

    events解析逻辑pluggable

    当一个文件全部读取到channel中,该文件会被重命名来标记已经读取完成或被删除。

    source是可靠的,不会丢失数据,即使Flume进程restartedkilled

    可靠地代价是:放到spoolingdirectory中的文件的文件名唯一(不能再被使用)且文件不能被修改。

Despitethe reliability guarantees of this source, there are still cases inwhich events may be duplicated if certain downstream failures occur.This is consistent with the guarantees offered by other Flumecomponents.

  • Twitter 1% firehose Source (highly experimental)

  • NetCat Source

Anetcat-like source ,监听指定的端口,把每一行文本转换为一个event

  • Sequence Generator Source

Usefulmainly for testing. 

  • Syslog Sources

Reads syslog data and generate Flume events.

The UDP source treats an entire message asa single event.

The TCP sources create a new event foreach string of characters separated by a newline (‘n’).

    • Syslog TCP Source

原始的、可靠地syslogTCP source

    • Multiport Syslog TCP Source

更新的、更快的、能够配置多端口的syslogTCP source

使用ApacheMina library实现高效地同时监听多个端口。

Providessupport for RFC-3164 and many common RFC-5424 formatted messages

Providesthe capability to configure the character set used on a per-portbasis

    • Syslog UDP Source

  • Http Source

Asource which accepts Flume Events by HTTP POSTand GET. GETshould be used for experimentation only.HTTP requests are converted into flume events by a pluggable“handler” which must implement the HTTPSourceHandler interface.This handler takes a HttpServletRequest and returns a list of flumeevents. All events handled from one Http request are committed to thechannel in one transaction, thus allowing for increased efficiency onchannels like the file channel. If the handler throws an exception,this source will return a HTTP status of 400.If the channel is full, or the source is unable to append events tothe channel, the source will return a HTTP 503- Temporarily unavailable status.

    • JSONHandler

默认handler,处理JSON格式events

支持UTF-8(默认)、UTF-16UTF-32字符集。

接收一个events数组(即使只有一个event),然后把他们转化成一个Flumeevent

    • BlobHandler

处理上传BinaryLarge Object (BLOB)的请求,例如PDFjpg

  • Legacy Sources(遗留的sources

允许1.x版本的Flumeagent0.9.4版本的Flumeagent接收events,将0.9.4版本的events格式转化成1.x版本的格式。

    • AvroLegacy Source

    • ThriftLegacy Source

  • Custom Source

自定义实现sourcesourcetype属性必须是自定义实现的全限定类名(FQCN)。

  • Scribe Source

Scribefacebook开源的日志收集系统)获取数据,sourcetype属性org.apache.flume.source.scribe.ScribeSource


Flume Sinks

  • HDFS Sink

目前支持创建textand sequence files,支持对这两种格式进行压缩。

CurrentlyFlume supports HDFS 0.20.2 and 0.23.

  • Logger Sink

Typicallyuseful for testing/debugging purpose

  • Avro Sink

主要应用场景

  • Thrift Sink

主要应用场景

  • IRC Sink

channel中的数据转发到配置的IRCdestinations

  • File Roll Sink

保存events到本地文件系统。

  • Null Sink

丢弃从channel接收的所有events

  • HBaseSinks

    • HbaseSink

    • AsyncHBaseSink

  • MorphlineSolrSink

Thissink extracts data from Flume events, transforms it, and loads it innear-real-time into Apache Solr servers

  • ElasticSearch Sink

Thissink writes data to an elasticsearch cluster

  • Kite Dataset Sink (experimental)

  • Custom Sink

自定义实现sinksinktype属性必须是自定义实现的全限定类名(FQCN)。


Flume Channels

  • Memory Channel

高吞吐量,agentfailure时会丢失channel中的数据。

  • JDBC Channel

目前支持内嵌的DerbyThisis a durable channel that’s ideal for flows where recoverability isimportant

  • File Channel

Channel数据支持化到本地磁盘。

支持数据加密。

  • Spillable Memory Channel

Channel中的数据首先保存在内存,分配的内存空间满了就保存在本地磁盘。

高吞吐量,agentfailure时会丢失channel中的数据。

Thischannel is currently experimental and not recommended for use inproduction.

  • Pseudo Transaction Channel

用于单元测试,不可用于生产环境。

  • Custom Channel

自定义实现channelchanneltype属性必须是自定义实现的全限定类名(FQCN)。


Flume Channel Selectors

  • Replicating Channel Selector (default)

复制events到与source连接的所有channel

a1.sources=r1

a1.channels=c1 c2 c3

a1.source.r1.selector.type=replicating

a1.source.r1.channels=c1 c2 c3

a1.source.r1.selector.optional=c3

以上配置,c3optionalchannel。数据写入c3失败会被忽略。数据写入c1c2失败会导致整个transaction失败。

  • Multiplexing Channel Selector

根据配置的header属性决定source中的events发送到哪一个channel或者哪些channels

  • Custom Channel Selector

自定义实现selectorselectortype属性必须是自定义实现的全限定类名(FQCN)。


Flume Sink Processors

Flume支持对sinks进行分组,将多个sinks合并到一个sinkgroup

Sinkprocessors的功能是:对一个sinkgroup内的所有sinks实现(1loadbalance2failover

  • Default Sink Processor

只接受一个sink,所以没有用,没有必要使用。

  • Failover Sink Processor

processor维护的每一个sink分配一个优先级,优先级不能重复,必须唯一。只要sinkgroup内有一个sink可用,events就会被发送出去。

Thefailover mechanism works by relegatingfailed sinks to a pool where they are assigned a cool down period,increasing with sequential failures before they are retried. Once asink successfully sends an event, it is restored to the live pool.

a1.sinkgroups=g1

a1.sinkgroups.g1.sinks=k1k2

a1.sinkgroups.g1.processor.type=failover

a1.sinkgroups.g1.processor.priority.k1=5

a1.sinkgroups.g1.processor.priority.k2=10

a1.sinkgroups.g1.processor.maxpenalty=10000


  • Load balancing Sink Processor

processorselector属性可以选择配置(1round_robin2random3)集成AbstractSinkSelector自定义实现的FQCN

通过配置processorbackoff属性,决定是否拉黑failsink

a1.sinkgroups=g1

a1.sinkgroups.g1.sinks=k1k2

a1.sinkgroups.g1.processor.type=load_balance

a1.sinkgroups.g1.processor.backoff=true

a1.sinkgroups.g1.processor.selector=random


  • 目前不支持CustomSink Processor


Event Serializers

file_rollhdfs这两种sink支持EventSerializer接口。

  • BodyText Serializer

不做任何转换和修改将eventbody写到输出流,header被忽略。

serializer只有一个属性appendNewline,表示是否添加换行,默认true

  • AvroEvent Serializer

events序列化到Avrocontainer file,支持Hadoop的数据压缩格式。


Flume Interceptors

Flume可以通过interceptorsflow中的events进行修改甚至丢弃。

  • TimestampInterceptor

eventheader中添加timestamp属性。

如果header中已经存在timestamp属性,可以通过配置选择保留或替换。

  • HostInterceptor

eventheader中添加host属性(该属性名可配置),属性值是运行agenthostnameIP

如果header中已经存在host属性,可以通过配置选择保留或替换。

  • StaticInterceptor

eventheader中添加固定的key-valuepair

  • UUIDInterceptor

eventheader中添加指定属性名,值是UUID

  • MorphlineInterceptor

处理模型如下图

  • RegexFiltering Interceptor

eventbody转换成text,然后使用配置的正则表达式对text进行匹配。

可以选择对匹配正则表达式的event进行includeexclude操作。

  • RegexExtractor Interceptor

提取正则表达式匹配的regexmatch groups,并添加到eventheader中。

If the Flume event body contained 1:2:3.4foobar5and the following configuration was used.

a1.sources.r1.interceptors.i1.regex=(\\d):(\\d):(\\d)

a1.sources.r1.interceptors.i1.serializers=s1 s2 s3

a1.sources.r1.interceptors.i1.serializers.s1.name=one

a1.sources.r1.interceptors.i1.serializers.s2.name=two

a1.sources.r1.interceptors.i1.serializers.s3.name=three

The extracted event will contain the same bodybut the following headers will have been added one=>1, two=>2,three=>3


Flume Properties

flume.called.from.service属性:如果指定了该属性,Flumeagent会在找不到配置文件时持续检测配置文件,否则,Flumeagent会终止。


Flume定期(30s)检测指定配置文件的变化。

Flumeagent在以下两种情况会加载新的配置:

  1. 第一次检测到配置文件

  2. 上一次检测后,配置文件的内容被修改

renamemove配置文件不会改变文件的modificationtime,不会被从新加载。


Log4J Appender

AppendsLog4j events to a flume agent’s avro source.


Load Balancing Log4J Appender

AppendsLog4j events to a list of flume agent’s avro source.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Go in memory

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值