標籤:log channel 可靠 擷取資料 ber ash 預設 x11 產生
Avro Source
監聽avro連接埠,接收外部avro用戶端資料流。跟前面的agent的Avro Sink可以組成多層拓撲結構。
| 12345678910111213141516 |
a1.sources=s1a1.sinks=k1a1.channels=c1 a1.sources.s1.channels=c1a1.sinks.k1.channel=c1 a1.sources.s1.type=avroa1.sources.s1.bind=vm1a1.sources.s1.port=41414 a1.sinks.k1.type=logger a1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100 |
啟動命令:
| 1 |
flume-ng agent --conf conf/ --conf-file conf/a1.conf --name a1 -Dflume.root.logger=INFO,console |
測試方法:
| 1 |
flume-ng avro-client --host vm1 --port 41414 --filename a.log |
Exec Source
啟動source的時候執行unix命令,並期望不斷擷取資料,比如tail -f命令。
Exec Source有可能會遺失資料,可以考慮使用Spooling Dircetory Source。
| 123456789101112131415 |
a1.sources=s1a1.sinks=k1a1.channels=c1 a1.sources.s1.channels=c1a1.sinks.k1.channel=c1 a1.sources.s1.type=execa1.sources.s1.command= tail -f /home/flume/a.log a1.sinks.k1.type=logger a1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100 |
執行命令:
| 1 |
flume-ng agent --conf conf/ --conf-file conf/a1.conf --name a1 -Dflume.root.logger=INFO,console |
測試方法:
向unix命令監聽的檔案追加內容,
| 1 |
echo ‘hello, everyone!‘ >> a.log |
Spooling Directory Source
監控某個檔案夾,將新產生的檔案解析成event,解析方式是可插拔的,預設是LINE,將新檔案中的每行資料轉換成一個event。檔案解析完成後,該檔案名稱字被追加.completed。
Spooling Dircetory Source相對於Exec Source更可靠,它不會遺失資料(甚至被重啟或殺死)。為了這種特性,只能是不可修改的、名字不重複的檔案才可使用這個source:
1)監控檔案夾內的檔案被flume使用後不能進行修改。
2)檔案名稱字不能重複,如果已經存在了xx.completed,不能在放入名字叫xx的檔案。否則報錯,停止。
3)被監控檔案夾裡的子檔案夾不處理
| 123456789101112131415 |
a1.sources=s1a1.sinks=k1a1.channels=c1 a1.sources.s1.channels=c1a1.sinks.k1.channel=c1 a1.sources.s1.type=spooldira1.sources.s1.spoolDir=/home/flume/a a1.sinks.k1.type=logger a1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100 |
啟動命令:
| 1 |
flume-ng agent --conf conf/ --conf-file conf/a1.conf --name a1 -Dflume.root.logger=INFO,console |
測試方法:
向/home/flume/a檔案夾內放入檔案。
Netcat Source
監聽連接埠資料。類似於nc -k -l [host] [port]命令.
| 12345678910111213141516 |
a1.sources=s1a1.sinks=k1a1.channels=c1 a1.sources.s1.channels=c1a1.sinks.k1.channel=c1 a1.sources.s1.type=netcata1.sources.s1.bind=localhosta1.sources.s1.port=41414 a1.sinks.k1.type=logger a1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100 |
啟動命令:
| 1 |
flume-ng agent --conf conf/ --conf-file conf/a1.conf --name a1 -Dflume.root.logger=INFO,console |
測試方式:
Sequence Generator Source
不斷產生從0開始的數字,主要用於測試
| 1234567891011121314 |
a1.sources=s1a1.sinks=k1a1.channels=c1 a1.sources.s1.channels=c1a1.sinks.k1.channel=c1 a1.sources.s1.type=seq a1.sinks.k1.type=logger a1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100 |
啟動命令:
| 1 |
flume-ng agent --conf conf/ --conf-file conf/a1.conf --name a1 -Dflume.root.logger=INFO,console |
Syslog Source
讀取syslog資料,它分為:Syslog TCP Source、Multiport Syslog TCP Source、Syslog UDP Source
| 12345678910111213141516 |
a1.sources=s1a1.sinks=k1a1.channels=c1 a1.sources.s1.channels=c1a1.sinks.k1.channel=c1 a1.sources.s1.type=syslogtcpa1.sources.s1.host=localhosta1.sources.s1.port=41414 a1.sinks.k1.type=logger a1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100 |
啟動命令:
| 1 |
flume-ng agent --conf conf/ --conf-file conf/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。
| 123456789101112131415 |
a1.sources=s1a1.sinks=k1a1.channels=c1 a1.sources.s1.channels=c1a1.sinks.k1.channel=c1 a1.sources.s1.type=httpa1.sources.s1.port=41414 a1.sinks.k1.type=logger a1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100 |
啟動命令:
| 1 |
flume-ng agent --conf conf/ --conf-file conf/a1.conf --name a1 -Dflume.root.logger=INFO,console |
測試方法:
| 1 |
curl -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都附帶著模式資訊
|
Flume Source 執行個體