对于结构化流,不显示“流”选项卡

时间:2019-05-09 04:30:49

标签: scala apache-spark spark-streaming spark-structured-streaming spark-ui

我正在使用结构化流媒体来读取csvs和写入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中的流指标?

1 个答案:

答案 0 :(得分:0)

要查看某些指标(在控制台中),您需要添加一个侦听器

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,显示有关偏移量,水印,源,接收器等的信息。

该视频可以为您提供帮助:Monitoring Structured Streaming Applications