StreamingListener技术点
以下是对StreamingListene的研究,由于比较简单,故只贴代码,不做解释
/**
* Created by gabry.wu on 2016/5/27.
* 实现StreamingListener,以监控spark作业状态
* 传入StreamingContext可以在某种出错时退出当前的SparkStreaming
*/
class StreamingMonitor(ssc:StreamingContext) extends StreamingListener{
private val log = LoggerFactory.getLogger("SparkStreamingMonitor")
// Receiver启动
override def onReceiverStarted(receiverStarted : StreamingListenerReceiverStarted): Unit = {
log.warn("onReceiverStarted")
log.warn(s"active=${receiverStarted.receiverInfo.active},executorId=${receiverStarted.receiverInfo.executorId}," +
s"lastError=${receiverStarted.receiverInfo.lastError},lastErrorMessage=${receiverStarted.receiverInfo.lastErrorMessage}," +
s"location=${receiverStarted.receiverInfo.location},name=${receiverStarted.receiverInfo.name}," +
s"streamId=${receiverStarted.receiverInfo.streamId}")
}
// Receiver报错
override def onReceiverError(receiverError : StreamingListenerReceiverError): Unit = {
log.warn("onReceiverError")
//可在该函数处理Receiver失败
log.warn(s"active=${receiverError.receiverInfo.active},executorId=${receiverError.receiverInfo.executorId}," +
s"lastError=${receiverError.receiverInfo.lastError},lastErrorMessage=${receiverError.receiverInfo.lastErrorMessage}," +
s"location=${receiverError.receiverInfo.location},name=${receiverError.receiverInfo.name}," +
s"streamId=${receiverError.receiverInfo.streamId}")
}
// Receiver停止
override def onReceiverStopped(receiverStopped : StreamingListenerReceiverStopped): Unit = {
log.warn("onReceiverStopped")
log.warn(s"active=${receiverStopped.receiverInfo.active},executorId=${receiverStopped.receiverInfo.executorId}," +
s"lastError=${receiverStopped.receiverInfo.lastError},lastErrorMessage=${receiverStopped.receiverInfo.lastErrorMessage}," +
s"location=${receiverStopped.receiverInfo.location},name=${receiverStopped.receiverInfo.name}," +
s"streamId=${receiverStopped.receiverInfo.streamId}")
}
// Batch提交作业
override def onBatchSubmitted(batchSubmitted : StreamingListenerBatchSubmitted): Unit = {
log.warn("onBatchSubmitted")
// 提交作业之前已经知道有多少数据
// batchSubmitted.batchInfo.numRecords是此次batch的数据量
log.warn(s"batchTime=${batchSubmitted.batchInfo.batchTime},numRecords=${batchSubmitted.batchInfo.numRecords}," +
s"processingDelay=${batchSubmitted.batchInfo.processingDelay},processingEndTime=${batchSubmitted.batchInfo.processingEndTime}," +
s"processingStartTime=${batchSubmitted.batchInfo.processingStartTime},schedulingDelay=${batchSubmitted.batchInfo.schedulingDelay}," +
s"submissionTime=${batchSubmitted.batchInfo.submissionTime},totalDelay=${batchSubmitted.batchInfo.totalDelay}")
}
// Batch启动
override def onBatchStarted(batchStarted : StreamingListenerBatchStarted): Unit = {
log.warn("onBatchStarted")
//batchStarted.batchInfo.schedulingDelay:从提交到正式启动batch的间隔时间
log.warn(s"batchTime=${batchStarted.batchInfo.batchTime},numRecords=${batchStarted.batchInfo.numRecords}," +
s"processingDelay=${batchStarted.batchInfo.processingDelay},processingEndTime=${batchStarted.batchInfo.processingEndTime}," +
s"processingStartTime=${batchStarted.batchInfo.processingStartTime},schedulingDelay=${batchStarted.batchInfo.schedulingDelay}," +
s"submissionTime=${batchStarted.batchInfo.submissionTime},totalDelay=${batchStarted.batchInfo.totalDelay}")
}
// Batch完成
override def onBatchCompleted(batchCompleted : StreamingListenerBatchCompleted): Unit = {
log.warn("onBatchCompleted")
//batchCompleted.batchInfo.processingDelay:批量处理时间
//batchCompleted.batchInfo.totalDelay:此次批处理从提交,到最后结束总耗时
log.warn(s"batchTime=${batchCompleted.batchInfo.batchTime},numRecords=${batchCompleted.batchInfo.numRecords}," +
s"processingDelay=${batchCompleted.batchInfo.processingDelay},processingEndTime=${batchCompleted.batchInfo.processingEndTime}," +
s"processingStartTime=${batchCompleted.batchInfo.processingStartTime},schedulingDelay=${batchCompleted.batchInfo.schedulingDelay}," +
s"submissionTime=${batchCompleted.batchInfo.submissionTime},totalDelay=${batchCompleted.batchInfo.totalDelay}")
}
// 输出操作开始
override def onOutputOperationStarted(outputOperationStarted : StreamingListenerOutputOperationStarted): Unit = {
log.warn("onOutputOperationStarted")
//outputOperationStarted.outputOperationInfo.description:其实就是Stack的部分信息,可用于输出Action的定位
//outputOperationStarted.outputOperationInfo.name:Action的函数名称
log.warn(s"batchTime=${outputOperationStarted.outputOperationInfo.batchTime},description=${outputOperationStarted.outputOperationInfo.description}," +
s"duration=${outputOperationStarted.outputOperationInfo.duration},endTime=${outputOperationStarted.outputOperationInfo.endTime}," +
s"failureReason=${outputOperationStarted.outputOperationInfo.failureReason},id=${outputOperationStarted.outputOperationInfo.id}," +
s"name=${outputOperationStarted.outputOperationInfo.name},startTime=${outputOperationStarted.outputOperationInfo.startTime}")
}
// 输出操作完成
override def onOutputOperationCompleted(outputOperationCompleted : StreamingListenerOutputOperationCompleted): Unit = {
log.warn("onOutputOperationCompleted")
//outputOperationCompleted.outputOperationInfo.duration:Action的耗时
//outputOperationCompleted.outputOperationInfo.failureReason:Action失败的原因。可以在该函数中处理Batch失败
log.warn(s"batchTime=${outputOperationCompleted.outputOperationInfo.batchTime},description=${outputOperationCompleted.outputOperationInfo.description}," +
s"duration=${outputOperationCompleted.outputOperationInfo.duration},endTime=${outputOperationCompleted.outputOperationInfo.endTime}," +
s"failureReason=${outputOperationCompleted.outputOperationInfo.failureReason},id=${outputOperationCompleted.outputOperationInfo.id}," +
s"name=${outputOperationCompleted.outputOperationInfo.name},startTime=${outputOperationCompleted.outputOperationInfo.startTime}")
}
}
下面是添加StreamingListene的代码
val ssc = new StreamingContext(sparkConf, new Duration(batchDuration))
ssc.addStreamingListener(new StreamingMonitor(ssc))
StreamingListener技术点的更多相关文章
- Spark大数据处理技术
全球首部全面介绍Spark及Spark生态圈相关技术的技术书籍 俯览未来大局,不失精细剖析,呈现一个现代大数据框架的架构原理和实现细节 透彻讲解Spark原理和架构,以及部署模式.调度框架.存储管理及 ...
- 关于解决python线上问题的几种有效技术
工作后好久没上博客园了,虽然不是很忙,但也没学生时代闲了.今天上博客园,发现好多的文章都是年终总结,想想是不是自己也应该总结下,不过现在还没想好,等想好了再写吧.今天写写自己在工作后用到的技术干货,争 ...
- SQL Server技术内幕笔记合集
SQL Server技术内幕笔记合集 发这一篇文章主要是方便大家找到我的笔记入口,方便大家o(∩_∩)o Microsoft SQL Server 6.5 技术内幕 笔记http://www.cnbl ...
- 本人提供微软系.NET技术顾问服务,欢迎企业咨询!
背景: 1:目前微软系.NET技术高端人才缺少. 2:企业很难直接招到高端技术人才. 3:本人提供.NET技术顾问,保障你的产品或项目在正确的技术方向. 技术顾问服务 硬服务项: 1:提供技术.决策. ...
- 分布式锁1 Java常用技术方案
前言: 由于在平时的工作中,线上服务器是分布式多台部署的,经常会面临解决分布式场景下数据一致性的问题,那么就要利用分布式锁来解决这些问题.所以自己结合实际工作中的一些经验和网上看到的一些资 ...
- 【大型网站技术实践】初级篇:借助LVS+Keepalived实现负载均衡
一.负载均衡:必不可少的基础手段 1.1 找更多的牛来拉车吧 当前大多数的互联网系统都使用了服务器集群技术,集群即将相同服务部署在多台服务器上构成一个集群整体对外提供服务,这些集群可以是Web应用服务 ...
- 探真无阻塞加载javascript脚本技术,我们会发现很多意想不到的秘密
下面的图片是我使用firefox和chrome浏览百度首页时候记录的http请求 下面是firefox: 下面是chrome: 在浏览百度首页前我都将浏览器的缓存全部清理掉,让这个场景最接近第一次访问 ...
- 关于如何提高Web服务端并发效率的异步编程技术
最近我研究技术的一个重点是java的多线程开发,在我早期学习java的时候,很多书上把java的多线程开发标榜为简单易用,这个简单易用是以C语言作为参照的,不过我也没有使用过C语言开发过多线程,我只知 ...
- 架构设计:远程调用服务架构设计及zookeeper技术详解(下篇)
一.下篇开头的废话 终于开写下篇了,这也是我写远程调用框架的第三篇文章,前两篇都被博客园作为[编辑推荐]的文章,很兴奋哦,嘿嘿~~~~,本人是个很臭美的人,一定得要截图为证: 今天是2014年的第一天 ...
随机推荐
- asp.net mvc,基于aop实现的接口访问统计、接口缓存等
其实asp.net 上aop现有的框架应该蛮多的,比如静态注入式的PostSharp(新版本好像已经商业化了,旧版本又不支持.net4.0+),或者通过反射的(性能会降低). 本文则是通过mvc其中一 ...
- Linux:iscsi存储服务器配置
服务器添加4块硬盘 mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde 记下UUID值 mdadm -D /de ...
- 用python写了一个猜年龄小游戏
写一个猜年龄游戏: 需要实现用户登录的功能 初始用户登录信息为 {'hades': '13579','nick': '123','ruixing': 'a1','fanping': 'b2'} 登录时 ...
- 第十一节:Web爬虫之数据存储(数据更新、删除、查询)
接着上一节的内容 5.MySQL数据更新 结果是将id=3的name进行更新操作,结果如下: 6.MySQL数据去重及更新 结果是判断数据是否有重复的,如果有重复的将不再存储,若没有重复的就更新数据进 ...
- 51NOD 1277 字符串中的最大值(KMP)
>>点击进入原题测试<< 思路:用KMP优化的暴力写了一遍,超时!没有充分利用KMP中next数组的性质. 首先这个题是肯定要用到KMP算法的,然后会有一个next[]数组. ...
- 百练2755:神奇的口袋(简单dp)
描述有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40.John现在有n个想要得到的物品,每个物品的体积分别是a1,a2……an.John可以从这些物品中选择一些 ...
- 数据库删除数据表重复数据,只留下ID较小的行
删除表中重复数据,留下ID比较小的行 delete from 表 where [重复字段] in (select [重复字段] from 表 group by 字段 having count([字段] ...
- codevs3411 洪水
题目描述 Description 小浣熊松松和朋友到野外露营,没想到遇上了π年一次的大洪水,好在松松是一只爱观察的小浣熊,他发现露营地的地形和洪水有如下性质: ①露营地可以被看做是一个N*M的矩形方阵 ...
- NOIP2012 提高组合集
NOIP 2012 提高组 合集 D1 T1 Vigenère 密码 模拟题,观察到两个数对应位置-1相加的和%26就是对应的字母,按照这个性质模拟即可. #include <iostream& ...
- 洛谷—— P1122 最大子树和
https://www.luogu.org/problem/show?pid=1122 题目描述 小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课 ...