flume学习(十):使用Morphline Interceptor

27 篇文章 0 订阅

1.Morphline是干嘛用的?
2.如何将message属性添加到event的headers当中?







Morphline是干嘛用的?简单点说就是一个ETL工具,详细介绍: http://kitesdk.org/docs/current/ ... ReferenceGuide.html

这里有一个注意点,是和cloudera search版本有关系的,我是用CDH 5.0.0, Parcel搭建的集群环境,对应装的cloudera search是1.0版本的,这个版本用的是kitesdk的morphlines,如果是更高版本的比如search1.3,可能用的就是cdk的morphlines了。用的哪个development kit对morphlines配置文件里面的那个 importCommands 配置是有讲究的,我用的kitesdk,所以应该写为: importCommands : ["org.kitesdk.**"],如果用的cdk的,则应该写为 importCommands : ["com.cloudera.**"],否则将无法导入commands。

还有一个小插曲就是,在研究flume-ng使用morphlines的过程中,每次启动agent都卡在importing commands上,不一会agent就挂掉了,这个问题纠结了很久,开始以为是search的相关jar包没有加载到classpath中去,导致无法导入commands,后面讲search的相关jar包都扔到flume的plugins.d插件目录下面了,还是不行。查看日志也没发现什么特别的异常,无意中发现了一个oom的异常,于是将agent的jvm调大为512M(cm装完默认agent的jvm只有50M),再重新启动agent,终于成功导入了commands,哎CM坑爹的默认配置折腾了我两天时间,不过还是研究各种官方文档学到了一些其他的知识,还是值得的。

下面贴出一个很简单的morphline.conf:
  1. morphlines : [
  2.   {
  3.     id : morphline1

  4.     # Import all morphline commands in these java packages and their subpackages.
  5.     # Other commands that may be present on the classpath are not visible to this morphline.
  6.     importCommands : ["org.kitesdk.**"]

  7.     commands : [
  8.         {
  9.                  readLine {
  10.                         charset : UTF-8
  11.                  }
  12.         }
  13.     ]
  14.   }
  15. ]
复制代码
只定义了一个kitesdk的一个command叫readLine(具体用法和解释参见: http://kitesdk.org/docs/current/ ... ReferenceGuide.html ),就是会将输入一行一行的读取,然后存放到一个叫message的键当中去。

接下来是一个简单的flume.conf:
  1. # Please paste flume.conf here. Example:

  2. # Sources, channels, and sinks are defined per
  3. # agent name, in this case 'tier1'.
  4. tier1.sources  = source1
  5. tier1.channels = channel1
  6. tier1.sinks    = sink1

  7. # For each source, channel, and sink, set
  8. # standard properties.
  9. tier1.sources.source1.type     = netcat
  10. tier1.sources.source1.bind     = 0.0.0.0
  11. tier1.sources.source1.port     = 9999
  12. tier1.sources.source1.channels = channel1
  13. tier1.sources.source1.interceptors = morphlineinterceptor
  14. tier1.sources.source1.interceptors.morphlineinterceptor.type = org.apache.flume.sink.solr.morphline.MorphlineInterceptor$Builder
  15. tier1.sources.source1.interceptors.morphlineinterceptor.morphlineFile = /etc/flume-ng/conf/morphline.conf
  16. tier1.sources.source1.interceptors.morphlineinterceptor.morphlineId = morphline1

  17. tier1.channels.channel1.type   = memory
  18. tier1.sinks.sink1.type         = logger
  19. tier1.sinks.sink1.channel      = channel1

  20. # Other properties are specific to each type of
  21. # source, channel, or sink. In this case, we
  22. # specify the capacity of the memory channel.
  23. tier1.channels.channel1.capacity = 100
复制代码
morphline interceptor的配置我直接摘自官方文档,主要注意一下那个morphlineFile就行了,把上面那个morphline.conf放到/etc/flume-ng/conf目录下面,morphlineId可以指定一个ID(如果morphline.conf中有配置多个ID的话),接下来启动agent。

然后telnet localhost 9999,输入hello world回车。

在agent的日志文件中就可以看到如下日志信息:

Event: { headers:{message=hello world} body: }注意这个message属性是添加到了event的headers当中了。



转自:

http://www.aboutyun.com/thread-12069-1-1.html

原文来自:

http://blog.csdn.net/xiao_jun_0820/article/details/40590189


flume学习(五):flume将log4j日志数据写入到hdfs
flume学习(六):使用hive来分析flume收集的日志数据
flume学习(七)、(八):如何使用event header中的key值以及自定义source
flume学习(九):自定义拦截器
flume学习(十):使用Morphline Interceptor
flume学习(十一):如何使用Spooling Directory Source
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值