Flume Source 实例
-
Avro Source
监听avro端口,接收外部avro客户端数据流。跟前面的agent的Avro Sink可以组成多层拓扑结构。
12345678910111213141516a1.sources=s1a1.sinks=k1a1.channels=c1a1.sources.s1.channels=c1a1.sinks.k1.channel=c1a1.sources.s1.type=avroa1.sources.s1.bind=vm1a1.sources.s1.port=41414a1.sinks.k1.type=loggera1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100启动命令:
1flume-ng agent --conf conf/ --conf-fileconf/a1.conf --name a1 -Dflume.root.logger=INFO,console测试方法:
1flume-ng avro-client --host vm1 --port 41414 --filename a.log -
Exec Source
启动source的时候执行unix命令,并期望不断获取数据,比如tail -f命令。
Exec Source有可能会丢失数据,可以考虑使用Spooling Dircetory Source。
123456789101112131415a1.sources=s1a1.sinks=k1a1.channels=c1a1.sources.s1.channels=c1a1.sinks.k1.channel=c1a1.sources.s1.type=execa1.sources.s1.command= tail -f /home/flume/a.loga1.sinks.k1.type=loggera1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100执行命令:
1flume-ng agent --conf conf/ --conf-fileconf/a1.conf --name a1 -Dflume.root.logger=INFO,console测试方法:
向unix命令监听的文件追加内容,
1echo'hello, everyone!'>> a.log -
Spooling Directory Source
监控某个文件夹,将新产生的文件解析成event,解析方式是可插拔的,默认是LINE,将新文件中的每行数据转换成一个event。文件解析完成后,该文件名字被追加.completed。
Spooling Dircetory Source相对于Exec Source更可靠,它不会丢失数据(甚至被重启或杀死)。为了这种特性,只能是不可修改的、名字不重复的文件才可使用这个source:
1)监控文件夹内的文件被flume使用后不能进行修改。
2)文件名字不能重复,如果已经存在了xx.completed,不能在放入名字叫xx的文件。否则报错,停止。
3)被监控文件夹里的子文件夹不处理
123456789101112131415a1.sources=s1a1.sinks=k1a1.channels=c1a1.sources.s1.channels=c1a1.sinks.k1.channel=c1a1.sources.s1.type=spooldira1.sources.s1.spoolDir=/home/flume/aa1.sinks.k1.type=loggera1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100启动命令:
1flume-ng agent --conf conf/ --conf-fileconf/a1.conf --name a1 -Dflume.root.logger=INFO,console测试方法:
向/home/flume/a文件夹内放入文件。
-
Netcat Source
监听端口数据。类似于nc -k -l [host] [port]命令.
12345678910111213141516a1.sources=s1a1.sinks=k1a1.channels=c1a1.sources.s1.channels=c1a1.sinks.k1.channel=c1a1.sources.s1.type=netcata1.sources.s1.bind=localhosta1.sources.s1.port=41414a1.sinks.k1.type=loggera1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100启动命令:
1flume-ng agent --conf conf/ --conf-fileconf/a1.conf --name a1 -Dflume.root.logger=INFO,console测试方式:
1telnet localhost 41414 -
Sequence Generator Source
不断生成从0开始的数字,主要用于测试
1234567891011121314a1.sources=s1a1.sinks=k1a1.channels=c1a1.sources.s1.channels=c1a1.sinks.k1.channel=c1a1.sources.s1.type=seqa1.sinks.k1.type=loggera1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100启动命令:
1flume-ng agent --conf conf/ --conf-fileconf/a1.conf --name a1 -Dflume.root.logger=INFO,console -
Syslog Source
读取syslog数据,它分为:Syslog TCP Source、Multiport Syslog TCP Source、Syslog UDP Source
12345678910111213141516a1.sources=s1a1.sinks=k1a1.channels=c1a1.sources.s1.channels=c1a1.sinks.k1.channel=c1a1.sources.s1.type=syslogtcpa1.sources.s1.host=localhosta1.sources.s1.port=41414a1.sinks.k1.type=loggera1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100启动命令:
1flume-ng agent --conf conf/ --conf-fileconf/a1.conf --name a1 -Dflume.root.logger=INFO,console测试方法:
需要syslog服务
-
Http Source
通过Http获取event,可以是GET、POST方式,GET方式应该在测试时使用。一个HTTP Request被handler解析成若干个event,这组event在一个事务里。
如果handler抛异常,http状态是400;如果channel满了,http状态是503。
123456789101112131415a1.sources=s1a1.sinks=k1a1.channels=c1a1.sources.s1.channels=c1a1.sinks.k1.channel=c1a1.sources.s1.type=httpa1.sources.s1.port=41414a1.sinks.k1.type=loggera1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100启动命令:
1flume-ng agent --conf conf/ --conf-fileconf/a1.conf --name a1 -Dflume.root.logger=INFO,console测试方法:
1curl -XPOST http://vm1:41414 -d'[{"headers" : {"timestamp" : "434324343","host" : "random_host.example.com"},"body" : "random_body"},{"headers" : {"namenode" : "namenode.example.com","datanode" : "random_datanode.example.com"},"body" : "really_random_body"}]'参数的格式是:
12345678910111213[{"headers" : {"timestamp" : "434324343","host" : "random_host.example.com"},"body" : "random_body"}, {"headers" : {"namenode" : "namenode.example.com","datanode" : "random_datanode.example.com"},"body" : "really_random_body"}]Http Source Handler:
Handler类型 说明 JSONHandler 默认值,将文本输入的每行转换成一个event BlobHandler 读取avro文件,将其中的每条avro记录转换成一个event,每个event都附带着模式信息

浙公网安备 33010602011771号