Siddhi 如何使用统计数据
Siddhi how to use statistics
最近我想让我的siddhi程序显示一些统计结果。然而效果并不好。
基本上我是按照this user guide to create an example app. Then I went to Siddhi Query Guide页面来添加统计部分的。主要 class 看起来像这样:
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();
但是输出没有显示流的计数和流速,而只是输出
[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}]
只有一个仪表,没有显示任何东西。我错过了任何扩展包吗?或者我以错误的方式使用 Statistics 命令?谢谢提问!
我只是想结束这个问题,因为我自己想出来了。当我将 Java 10 用作 JDK 时,出现了这个问题。解决办法是用java 1.8
最近我想让我的siddhi程序显示一些统计结果。然而效果并不好。
基本上我是按照this user guide to create an example app. Then I went to Siddhi Query Guide页面来添加统计部分的。主要 class 看起来像这样:
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();
但是输出没有显示流的计数和流速,而只是输出
[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}]
只有一个仪表,没有显示任何东西。我错过了任何扩展包吗?或者我以错误的方式使用 Statistics 命令?谢谢提问!
我只是想结束这个问题,因为我自己想出来了。当我将 Java 10 用作 JDK 时,出现了这个问题。解决办法是用java 1.8