我正在使用结构化流进行读取CSV并写入Kafka。"流"选项卡没有在Spark UI中显示(不使用流上下文(。
val userSchema = new StructType().add("name", "string").add("age", "integer")
val csvDF = spark
.readStream
.option("sep", ";")
.schema(userSchema) // Specify schema of the csv files
.csv("/path/to/directory")
如何在UI中获得流量指标?
要查看一些指标(在控制台(,您需要添加一个侦听器
spark.streams.addListener(new StreamingQueryListener {
override def onQueryStarted(event: StreamingQueryListener.QueryStartedEvent): Unit = logger.debug(s"QueryStarted [id = ${event.id}, name = ${event.name}, runId = ${event.runId}]")
override def onQueryProgress(event: StreamingQueryListener.QueryProgressEvent): Unit = logger.warn(s"QueryProgress ${event.progress}")
override def onQueryTerminated(event: StreamingQueryListener.QueryTerminatedEvent): Unit = logger.debug(s"QueryTerminated [id = ${event.id}, runId = ${event.runId}, error = ${event.exception}]")
})
QueryProgressEvent
,显示有关偏移,水印,来源,水槽等的信息
此视频可以为您提供帮助:监视结构化流式应用程序