【问题标题】:hdfs-sink: how to get rid of the timestamp added in every event by flume in the HDFS fileshdfs-sink:如何摆脱 HDFS 文件中 Flume 在每个事件中添加的时间戳
【发布时间】:2017-09-13 04:43:21
【问题描述】:

我有一些文件,每行都包含 json

[root@ip-172-29-1-12 vp_flume]# more vp_170801.txt.finished | awk '{printf("%s\n", substr($0,0,20))}'
{"status":"OK","resp
{"status":"OK","resp
{"status":"OK","resp
{"status":"OK","resp
{"status":"OK","resp
{"status":"OK","resp
{"status":"OK","resp
{"status":"OK","resp
{"status":"OK","resp
{"status":"OK","resp

我的水槽配置是

[root@ip-172-29-1-12 flume]# cat flume_test.conf 
agent.sources = seqGenSrc
agent.channels = memoryChannel
agent.sinks = loggerSink

agent.sources.seqGenSrc.type = spooldir
agent.sources.seqGenSrc.spoolDir = /moveitdata/dong/vp_flume
agent.sources.seqGenSrc.deserializer.maxLineLength = 10000000
agent.sources.seqGenSrc.fileSuffix = .finished
agent.sources.seqGenSrc.deletePolicy = never

agent.sources.seqGenSrc.channels = memoryChannel
agent.sinks.loggerSink.channel = memoryChannel
agent.channels.memoryChannel.type = memory
agent.channels.memoryChannel.capacity = 100

agent.sinks.loggerSink.type = hdfs
agent.sinks.loggerSink.hdfs.path = /home/dong/vp_flume

agent.sinks.loggerSink.hdfs.writeFormat = Text
agent.sinks.loggerSink.hdfs.rollInterval = 0
agent.sinks.loggerSink.hdfs.rollSize = 1000000000
agent.sinks.loggerSink.hdfs.rollCount = 0

HDFS 中的文件是:

[root@ip-172-29-1-12 flume]# hadoop fs -text /home/dong/vp_flume/* | awk '{printf("%s\n", substr($0,0,20))}' | more
1505276698665   {"stat
1505276698665   {"stat
1505276698666   {"stat
1505276698666   {"stat
1505276698666   {"stat
1505276698667   {"stat
1505276698667   {"stat
1505276698667   {"stat
1505276698668   {"stat
1505276698668   {"stat
1505276698668   {"stat
1505276698668   {"stat
1505276698669   {"stat
1505276698669   {"stat
1505276698669   {"stat
1505276698669   {"stat
1505276698670   {"stat
1505276698670   {"stat
1505276698670   {"stat
1505276698670   {"stat

问题:我不喜欢flume在每个事件中添加的时间戳。但是,如何通过正确配置flume来摆脱它呢?

【问题讨论】:

    标签: flume-ng


    【解决方案1】:

    您没有在代理配置文件中明确提到 hdfs.fileType 属性,因此 Flume 将默认使用 SequenceFile。 SequenceFile 支持两种写入格式:TextWritable。你已经设置了hdfs.writeFormat = Text,这意味着Flume 将使用HDFSTextSerializer 来序列化你的事件。如果您查看its source(第 53 行),您会看到它添加了一个时间戳作为默认键。

    使用hdfs.writeFormat = Writable 也无济于事,因为它的作用相同。您可以查看其来源here(第 52 行)。

    SequenceFile 始终需要密钥。因此,除非您有充分的理由使用 SequenceFile,否则我建议您在代理配置中使用 hdfs.fileType = DataStream

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 2019-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多