Flume数据推送(Push)
来源:互联网 发布:手机淘宝卖家推荐 编辑:程序博客网 时间:2024/05/21 11:01
一直都是用flume的pull方式收集日志数据,为了便于以后对业务系统实时日志收集的扩展,今天研究了下push方式的日志收集。
1.首先agent端应该配置以下几种source(监听TCP/UDP端口):
syslogUdp(port)
监听Udp端口
syslogTcp(port)
监听Tcp端口
syslogTcp1(port)
只监听Tcp端口的一个链接
2.然后在业务端直接向所配置的端口发送数据即可
大致如下:
Socket client = new Socket("10.64.49.198", 23456);OutputStream out = client.getOutputStream();String event = "<4>hello\n";out.write(event.getBytes());out.flush();out.close();client.close();
所发送的event格式必需为如下格式
“<n>event_content\n”
在collector端console输出内容如下
"{ syslogfacility : n/8 } { syslogseverity : n%8 } event_content"
其中
syslogfacility = n/8
syslogseverity = n%8
假如event的内容为:"<4>hello\n"
输出为:"{ syslogfacility : 0 } { syslogseverity : 4 } hello"
源码中具体解析类为com.cloudera.flume.handlers.syslog.SyslogWireExtractor
/** * This is basically a state machine implementation of the extract function. * It uses a DataInputStream instead of a string to avoid the cost of string * and character encoding */ public Event extract(DataInputStream in) throws EventExtractException { Preconditions.checkNotNull(in); Mode m = Mode.START; StringBuilder prio = new StringBuilder(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte b = 0; long cnt = 0; try { while (true) { b = in.readByte(); cnt++; switch (m) { case START: if (b == '<') { m = Mode.PRIO; } else { m = Mode.ERR; } break; case PRIO: if (b == '>') { m = Mode.DATA; } else { char ch = (char) b; if (Character.isDigit(ch)) { prio.append(ch); // stay in PRIO mode } else { m = Mode.ERR; } } break; case DATA: if (b == '\n') { Event e = buildEvent(prio, baos); return e; } baos.write(b); break; case ERR: // read until we get to a \n if (b == '\n') { throw new EventExtractException( "Failed to extract syslog wire entry"); } // stay in Mode.ERR; break; } } } catch (EOFException e) { switch (m) { case ERR: // end of stream but was in error state? Throw extraction exception throw new EventExtractException("Failed to extract syslog wire entry"); case DATA: // end of stream but had data, return it. return buildEvent(prio, baos); default: // if not in error state just return done; return null; } } catch (IOException e) { throw new EventExtractException("Failed to extract syslog wire entry: " + e.getMessage()); } }
- Flume数据推送(Push)
- Flume监控的数据Push推送给SparkStreaming(Scala版本)
- Flume推送数据到SparkStreaming
- ZK Server Push实现数据主动推送
- 消息推送(Server Push)
- 消息推送(push原理)
- Push推送
- Push推送
- 推送-PUSH
- Push推送
- Flume连接oracle实时推送数据到kafka
- iphone push notification 消息推送(转)
- iOS 远程推送(Push Notification)实现
- 使用Spring BlazeDS Integration进行数据推送服务(push data)
- 使用Spring BlazeDS Integration进行数据推送服务(push data)
- Android 消息推送 -- Xinge Push[客户端数据接收处理]
- SparkStreaming整合Flume(一)Push方式的整合
- flume-Spark整合-push方式
- JSP页面中嵌入flash
- Cortex-M3学习日志(一)-- GPIO实验1
- 使用Maven2进行单元测试
- 云计算的规范
- Linux驱动程序头文件
- Flume数据推送(Push)
- Lisp编程环境的搭建
- 【转】ARM 时钟的三种模式
- ARM体系结构与汇编100问(三)
- 85后大学生2800元起家创业 "捞偏门"年赚1500万
- 十五周作业1
- ARM启动代码分析
- 额,新闻新闻
- 深入理解Java调试体系