简体   繁体   English

Spark 结构化流 UI 的自定义选项卡

[英]Custom tab for Spark Structured streaming UI

I have created a Custom Streaming tab for Spark Structured streaming.我为 Spark 结构化流创建了一个自定义流选项卡。 I have just attached the streaming Tab in Spark UI but i am not able to attach page in streaming tab.我刚刚在 Spark UI 中附加了流式选项卡,但我无法在流式选项卡中附加页面。 In this custom tab, i want to show how many batches has completed, number of messages coming per batch, Processing Time and its graph.在此自定义选项卡中,我想显示已完成的批次数、每批次收到的消息数、处理时间及其图表。 Through SQL listener and StreamingQueryListener i can get the information and want to add in streaming tab.通过 SQL 侦听器和 StreamingQueryListener 我可以获得信息并希望添加到流选项卡中。

public class CustomTab extends SparkUITab {

public CustomTab(SparkUI parent, String prefix) {
    super(parent, prefix);
}

public static void getCustomTab(JobContext jobcontext) {
    SparkContext sparkContext = jobcontext.getSparkSession().sparkContext();

    StreamingContext ssc = new StreamingContext(sparkContext, new Duration(1000));
    StreamingTab streamingTab = new StreamingTab(ssc);

    sparkContext.ui().get().attachPage(new CustomPage("customPage", streamingTab));

    if (sparkContext.ui().isDefined()) {
        sparkContext.ui().get().attachTab(streamingTab);

    } 
}

} }

I am getting issue while attaching customPage in custom streaming tab.我在自定义流媒体选项卡中附加 customPage 时遇到问题。 render method of SparkUITab is not called by SparkUI. SparkUI 不调用 SparkUITab 的 render 方法。 Second issue I am getting is that how to change scala.xml.Node class in Java. I mean is there any class in java that I can use instead of Node class or how to add String in scala.xml.Node. Second issue I am getting is that how to change scala.xml.Node class in Java. I mean is there any class in java that I can use instead of Node class or how to add String in scala.xml.Node.

If there is any Java class that I can use, so how to change back to Seq of Node.如果有什么Java class我可以用,那么怎么改回Node.js的Seq。

class CustomPage extends WebUIPage {

StreamingTab streamingTab = null;

public CustomPage(String prefix, StreamingTab sparkUI) {
    super(prefix);
    this.streamingTab = sparkUI;
}

@Override
public Seq<Node> render(HttpServletRequest request) {
    System.out.println("In render method");

    String value = "This text is going to come at the bottom";
    Option<String> optionSome = Option.apply(value);

    Function0<Seq<Node>> length = new AbstractFunction0<Seq<Node>>() {

        @Override
        public Seq<Node> apply() {
            scala.xml.Node node = null;
        //  I am not getting that how to add html code("<div> { <div id=\"custommmmmm\"></div> }  </div>") here
            return null;
        }

    };

    return UIUtils.headerSparkPage("custom", length, this.streamingTab, null, optionSome, false, false);
}

} }

Is it possible to show structured streaming batches, its processing time and no of rows per batch through listeners and if possible then which listener should i use and how to add that in my custom page.是否可以通过侦听器显示结构化流批次、处理时间和每批次的行数,如果可能的话,我应该使用哪个侦听器以及如何将其添加到我的自定义页面中。

You can use StreamingQueryListener for your use case.您可以将 StreamingQueryListener 用于您的用例。 You'll have to persist the data you get from StreamingQueryListener and then you can display them in your Custom tab.您必须保留从 StreamingQueryListener 获得的数据,然后才能在“自定义”选项卡中显示它们。

Use the class Text - see the example:使用 class 文本 - 请参见示例:

UIUtils.headerSparkPage(request,
                "My page",
                () -> new Text("my custom page content"), parent, Option.apply("help text"),false, false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM