SparkStreaming 监控文件目录
object SparkStreaming_TextFile {
def main(args: Array[String]): Unit = {
Logger.getLogger("org.apache.spark").setLevel(Level.WARN)
Logger.getLogger("org.eclipse.jetty.server").setLevel(Level.OFF)
val conf = new SparkConf().setMaster("spark://hmaster:7077")
.setAppName(this.getClass.getSimpleName)
.set("spark.executor.memory", "2g")
.set("spark.cores.max", "8")
.setJars(Array("E:\\ScalaSpace\\Spark_Streaming\\out\\artifacts\\Spark_Streaming.jar"))
val context = new SparkContext(conf)
//step1 create streaming context
val ssc = new StreamingContext(context,Seconds(10))
//step2 监控特定目录
val lines = ssc.textFileStream("hdfs://hmaster:9000/zh/logs/")
val words = lines.flatMap(_.split(" ")).map(x => (x,1)).reduceByKey(_ + _)
words.print()
ssc.start()
ssc.awaitTermination()
}
}
def fileStream[
K: ClassTag,
V: ClassTag,
F <: NewInputFormat[K, V]: ClassTag
] (directory: String, filter: Path => Boolean, newFilesOnly: Boolean): InputDStream[(K, V)] = {
new FileInputDStream[K, V, F](this, directory, filter, newFilesOnly)
}
val dataStream = ssc.fileStream[LongWritable, Text, TextInputFormat](directory,(x : Path) => {
println(x.getName)
x.getName.contains(".txt")
},true)
如下图所示,这也是为什么spark中已经存在的文件不能够再次读取的原因。
当文件名存在时,spark将会记录文件,并不会更新它的时间,故而时间的过滤不满足。
/** If given key is already in this map, returns associated value.
*
* Otherwise, computes value from given expression `op`, stores with key
* in map and returns that value.
* @param key the key to test
* @param op the computation yielding the value to associate with `key`, if
* `key` is previously unbound.
* @return the value associated with key (either previously or as a result
* of executing the method).
*/
def getOrElseUpdate(key: A, op: => B): B =
get(key) match {
case Some(v) => v
case None => val d = op; this(key) = d; d
}
SparkStreaming 监控文件目录的更多相关文章
- Flume实时监控目录sink到hdfs,再用sparkStreaming监控hdfs的这个目录,对数据进行计算
目标:Flume实时监控目录sink到hdfs,再用sparkStreaming监控hdfs的这个目录,对数据进行计算 1.flume的配置,配置spoolDirSource_hdfsSink.pro ...
- inotifywait实时监控文件目录
一.inotify简介 inotify 是一种强大的.细粒度的.异步文件系统监控机制,它满足各种各样的文件监控需要,可以监控文件系统的访问属性.读写属性.权限属性.创建删除.移动等操作,也可以监控文件 ...
- C#实现对文件目录的实时监控
本文主要描述如何通过C#实现实时监控文件目录下的变化,包括文件和目录的添加,删除,修改和重命名等操作. 首先,我们需要对.net提供的FileSystemWatcher类有所了解.我有些懒,找了MSD ...
- 大数据系统之监控系统(二)Flume的扩展
一些需求是原生Flume无法满足的,因此,基于开源的Flume我们增加了许多功能. EventDeserializer的缺陷 Flume的每一个source对应的deserializer必须实现接口E ...
- C#使用FileSystemWatcher控件实现的文件监控功能示例
本文实例讲述了C#使用FileSystemWatcher控件实现的文件监控功能.分享给大家供大家参考,具体如下: FileSystemWatcher 可以使用FileSystemWatcher组件监视 ...
- 第1节 flume:7、flume的监控文件夹,实现数据收集到hdfs上
1.2.2 采集案例 1.采集目录到HDFS 需求分析 结构示意图: 采集需求:某服务器的某特定目录下,会不断产生新的文件,每当有新文件出现,就需要把文件采集到HDFS中去 根据需求,首先定义以下3大 ...
- linux定时备份mysql并同步到其它服务器
数据在任何一家公司里面都是最核心的资产,定期备份则是为了保证数据库出现问题的时候能够及时回滚到最近的备份点,将损失缩小到最小 这篇文章将会两部分来说明:1.mysql的定期备份:2.同步到其它服务器 ...
- 通过rsync+inotify实现数据的实时备份
我讲到过利用rsync实现数据的镜像和备份,但是要实现数据的实时备份,单独靠rsync还不能实现,本文就讲述下如何实现数据的实时备份. 一.rsync的优点与不足 与传统的cp.tar备份方式相比,r ...
- Rsync+Inotify-tools实现数据实时同步
inotify是一种强大的,细粒度的,异步文件系统时间监控机制,它可以替代crond实现与rsync的触发式文件同步,从而监控文件系统中添加,删除,修改,移动等细粒事件,从LINUX 2.6.13起, ...
随机推荐
- python模块部分 re模块 之正则表达式
python 全栈开发 1.什么是模块 2.正则表达式 一.什么是模块? 1.模块: 是一组功能的集合 你要和一个东西打交道,但是这个东西本身和python没有关系,这个东西本身就存在, 这时,pyt ...
- python3替换文件的内容
目标:替换文件中的字符串内容 方法1:使用fileinput包 import fileinput for line in fileinput.input(“要修改的文件名", inp ...
- zabbix监控指定端口
生产上经常会监控某些具体端口状态,下面介绍具体步骤: 主机名 ip 操作系统 zabbix版本 zabbix-server 172.27.9.63 Centos7.3.1611 zabbix_serv ...
- 用两个栈实现队列(python)
题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. # -*- coding:utf-8 -*- class Solution: def __init__( ...
- 1. Two Sum (快速排序;有序数组的查找: 两个指针; 哈希表)
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- TZOJ 1321 Girls and Boys(匈牙利最大独立集)
描述 the second year of the university somebody started a study on the romantic relations between the ...
- 如何成功再次安装MYSQL
以前安过,后来再安装就是停在启动项就是过不去,无响应 弄了两天,期待奇迹,网上各种教程试了个遍就是不行,大体就是删除INI,清理注册表,以下是新的发现:(转载) 如果你的电脑里装过MySQL,想再重新 ...
- 项目总结01:JSP mysql SpringMvc下中国省市县三级联动下拉框
JSP mysql SpringMvc下中国省市县三级联动下拉框 关键词 JSP mysql数据库 SpringMvc ajax Controller层 Service层 中国地区 省 ...
- 【centos】centos安装配置samba
因为我的centos为一台阿里云服务器,想和我本机(mac)进行文件共享.所以在我的阿里云上安装配置samba. 服务器环境:centos 7.3 本地环境:mac 第1步:首先查看是否已经安装过了s ...
- nginx配置websocket
有时候我们需要给websocket服务端做一下nginx的配置,比如需要给websocket服务端做负载均衡,或者,有些系统要求访问websocket的时候不能带端口,这时候我们就需要用nginx来进 ...