Search code examples
javasiddhi

Siddhi how to use statistics


Recently I want my siddhi program to show some statistic result. 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. 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!


Solution

  • I just want to close this question as I figured it out myself. This problem happened as I used Java 10 as JDK. The solution is to use java 1.8