1、目标场景

2、flume agent配置文件

#  define agent name, source/sink/channel name
a1.sources = r1
a1.sinks = k1
a1.channels = c1 # source,http,jsonhandler
a1.sources.r1.type = http
a1.sources.r1.bind = master
a1.sources.r1.port =
a1.sources.r1.handler = org.apache.flume.source.http.JSONHandler # 03 timestamp and host interceptors work before source
a1.sources.r1.interceptors = i1 i2 # 两个interceptor串联,依次作用于event
a1.sources.r1.interceptors.i1.type = timestamp
a1.sources.r1.interceptors.i1.preserveExisting = false a1.sources.r1.interceptors.i2.type = host
# flume event的头部将添加 “hostname”:实际主机名
a1.sources.r1.interceptors.i2.hostHeader = hostname
# 指定key,value将填充为flume agent所在节点的主机名
a1.sources.r1.interceptors.i2.useIP
= false # IP和主机名,二选一即可 # hdfs sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://master:9000/flume/%Y-%m-%d/ # hdfs sink将根据event header中的时间戳进行替换
# 和hostHeader的值保持一致,hdfs sink将提取event中key为hostnmae的值,基于该值创建文件名前缀
a1.sinks.k1.hdfs.filePrefix = %{hostname} # hdfs sink将根据event header中的hostnmae对应的value进行替换
a1.sinks.k1.hdfs.fileType = DataStream
a1.sinks.k1.hdfs.writeFormat = Text
a1.sinks.k1.hdfs.rollInterval =
a1.sinks.k1.hdfs.rollCount =
a1.sinks.k1.hdfs.rollSize = # channel,memory
a1.channels.c1.type = memory
a1.channels.c1.capacity =
a1.channels.c1.transactionCapacity = # bind source,sink to channel
a1.sinks.k1.channel = c1
a1.sources.r1.channels = c1

3、验证timestamp+host interceptor

验证思路:

1)先将interceptor作用后的event,通过logger sink打印到console,验证header是否正常添加
2)修改sink为hdfs, 观察目录和文件的名称是否能够按照预期创建(时间戳-目录,hostname-文件前缀)

验证过程:

1)发送header为空的http请求,logger sink打印event到终端,观察event header中是否被添加了timestamp以及hostname

2)ogger打印到console的event,header发生了变化

3)修改sink为hdfs, 观察HDFS的目录名(时间戳)和文件前缀(hostnme)

*目录名被正常替换(基于event header中的时间戳)

*文件前缀被正常替换(基于event header中的hostname:实际主机名)

* 文件内容被写入为event的body

06_Flume_interceptor_时间戳+Host的更多相关文章

  1. kafka笔记-Kafka在zookeeper中的存储结构【转】

    参考链接:apache kafka系列之在zookeeper中存储结构  http://blog.csdn.net/lizhitao/article/details/23744675 1.topic注 ...

  2. kafka在zookeeper中的存储结构

    参考site:http://kafka.apache.org/documentation.html#impl_zookeeper 1.zookeeper客户端相关命令 在确保zookeeper服务启动 ...

  3. 快速搭建日志系统——ELK STACK

    什么是ELK STACK ELK Stack是Elasticserach.Logstash.Kibana三种工具组合而成的一个日志解决方案.ELK可以将我们的系统日志.访问日志.运行日志.错误日志等进 ...

  4. flume组件汇总 source、sink、channel

    Flume Source Source类型 说明 Avro Source 支持Avro协议(实际上是Avro RPC),内置支持 Thrift Source 支持Thrift协议,内置支持 Exec  ...

  5. apache kafka系列之在zookeeper中存储结构

    1.topic注册信息 /brokers/topics/[topic] : 存储某个topic的partitions所有分配信息 Schema:   {    "version": ...

  6. Kafka学习之路 (五)Kafka在zookeeper中的存储

    一.Kafka在zookeeper中存储结构图 二.分析 2.1 topic注册信息 /brokers/topics/[topic] : 存储某个topic的partitions所有分配信息 [zk: ...

  7. kafka在zookeeper中存储结构

    1.topic注册信息 /brokers/topics/[topic] : 存储某个topic的partitions所有分配信息 Schema:   {    "version": ...

  8. Kafka(四)Kafka在zookeeper中的存储

    一 Kafka在zookeeper中存储结构图 二 分析 2.1 topic注册信息 /brokers/topics/[topic] : 存储某个topic的partitions所有分配信息 [zk: ...

  9. tcpdump学习笔记

    简介     简单的说,tcpdump就是一个抓包工具,类似Wireshark.     tcpdump可以根据使用者的定义过滤/截取网络上的数据包,并进行分析.tcpdump可以将数据包的头部完全接 ...

随机推荐

  1. VUX

    1.mapState 2.mapGetters 3. 4. 当你的操作行为中含有异步操作,比如向后台发送请求获取数据,就需要使用action的dispatch去完成.其他使用commit即可. 举个例 ...

  2. 使用Python2.7 POST 数据到 onenet 平台

    功能 发送数据名称为SENSORID(这里用TEST测试),数值为VALUE(这里用49值做测试)的数据,发送到自己的onenet对应设备 效果发送成功 代码 # -*- coding: utf-8 ...

  3. JavaScript加强

    1.Aptana简介 Aptana是一个非常强大,开源,专注于JavaScript的Ajax开发IDE它的特性包括 1.JavaScript,JavaScript函数,HTML,CSS语言的Code  ...

  4. [LeetCode] 804. Unique Morse Code Words_Easy tag: Hash Table

    International Morse Code defines a standard encoding where each letter is mapped to a series of dots ...

  5. 用python与文件进行交互

    一.文件处理 1.介绍 计算机系统:计算机硬件,操作系统,应用程序 应用程序无法直接操作硬件,通过操作系统来操作文件,进而读/写硬件中的文件. python打开文件过程: #打开 f=open('a. ...

  6. How to install MVVM Light Toolkit via NuGet

    Here is how you can install MVVM Light Toolkit  via NuGet in an easy way using only Visual Studio. S ...

  7. 使用i5ting_toc 预览 markdown 文件

    i5ting_toc__tree https://github.com/i5ting/i5ting_ztree_toc 是去哪儿网前段架构师狼叔编写的一个jQuery插件,用于将markdown 转化 ...

  8. GetLastError函数

      错误代码各个位数的意义:GetLastError函数返回值!SetLastError可是设置这个错误代码. 位 31-30 29 28 27-16 15-0 内容 严重性 Micorsoft/ 客 ...

  9. git参考文档

    ==================================================================================================== ...

  10. input文本框只能输入数字

    HTML中的input文本框有时候需要数字的做输入检查,如果能做输入之前限定只能输入数字的话,就可以省去在提交时候的输入内容检查了. 下面是自己在火狐浏览器上调试出的实现,实现原理就是在键盘事件(on ...