简体   繁体   English

悉达如何使用统计

[英]Siddhi how to use statistics

Recently I want my siddhi program to show some statistic result. 最近,我希望我的siddhi程序显示一些统计结果。 However it did not work out really well. 但是,效果不是很好。

Basically I followed this user guide to create an example app. 基本上,我遵循此用户指南来创建示例应用程序。 Then I went to Siddhi Query Guide page to add the statistics part. 然后我去了Siddhi Query Guide页面,添加了统计部分。 The main class looks like this: 主类如下所示:

    String siddhiApp = 
            "@App:name('TestApp') " + 
            "@App:statistics(interval = '1') " + 
            "define stream StockEventStream (symbol string, price float, volume long); " +
            " " +
            "@info(name = 'query1') " +
            "from StockEventStream#window.length(5) " +
            "select symbol, sum(price) as price, sum(volume) as volume " +
                    "group by symbol " +
            "insert into AggregateStockStream ;";

    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

    siddhiAppRuntime.addCallback("AggregateStockStream", new StreamCallback() {
        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
    }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockEventStream");

    //Start SiddhiApp runtime
    siddhiAppRuntime.start();

    //Sending events to Siddhi
    inputHandler.send(new Object[]{"IBM", 100f, 100L});
    Thread.sleep(1000);
    inputHandler.send(new Object[]{"IBM", 200f, 300L});
    inputHandler.send(new Object[]{"WSO2", 60f, 200L} );
    Thread.sleep(1000);
    inputHandler.send(new Object[]{"WSO2", 70f, 400L});
    inputHandler.send(new Object[]{"GOOG", 50f, 30L});
    Thread.sleep(1000);
    inputHandler.send(new Object[]{"IBM", 200f, 400L});
    Thread.sleep(2000);
    inputHandler.send(new Object[]{"WSO2", 70f, 50L});
    Thread.sleep(2000);
    inputHandler.send(new Object[]{"WSO2", 80f, 400L});
    inputHandler.send(new Object[]{"GOOG", 60f, 30L});

    //Shutdown SiddhiApp runtime
    siddhiAppRuntime.shutdown();

    //Shutdown Siddhi
    siddhiManager.shutdown();

However the output did not show the count and flow rate of the stream instead the output was only 但是,输出未显示流的数量和流率,而仅显示了

[Event{timestamp=1523613242078, data=[IBM, 100.0, 100], isExpired=false}]
[Event{timestamp=1523613243107, data=[IBM, 300.0, 400], isExpired=false}]
[Event{timestamp=1523613243107, data=[WSO2, 60.0, 200], isExpired=false}]
[Event{timestamp=1523613244107, data=[WSO2, 130.0, 600], isExpired=false}]
[Event{timestamp=1523613244107, data=[GOOG, 50.0, 30], isExpired=false}]

2018/4/13 下午5:54:05 
============================================================

-- Gauges ----------------------------------------------------------------------
org.wso2.siddhi.SiddhiApps.TestApp.Siddhi.Queries.query1.memory

[Event{timestamp=1523613245120, data=[IBM, 400.0, 700], isExpired=false}]
[Event{timestamp=1523613247136, data=[WSO2, 200.0, 650], isExpired=false}]
[Event{timestamp=1523613249137, data=[WSO2, 220.0, 850], isExpired=false}]
[Event{timestamp=1523613249137, data=[GOOG, 110.0, 60], isExpired=false}]

There is only a Gauge without showing anything. 只有一个量规而不显示任何东西。 Did I miss any extension package? 我错过任何扩展包了吗? Or am I using Statistics command in wrong way? 还是我以错误的方式使用了统计命令? Thank you for asking! 谢谢你的慰问!

I just want to close this question as I figured it out myself. 我只是想自己解决这个问题。 This problem happened as I used Java 10 as JDK. 当我将Java 10用作JDK时,发生了此问题。 The solution is to use java 1.8 解决方法是使用Java 1.8

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

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