Example #1
0
        public void SetUp()
        {
            var container = ContainerExtensions.CreateDefaultContainer()
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            var configuration = new Configuration(container);

            configuration.Common.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.CASE_INSENSITIVE;
            configuration.Common.AddEventType("StockTick", typeof(StockTick).FullName);
            _runtime = EPRuntimeProvider.GetRuntime("TestStockTickerRSI", configuration);
            _runtime.Initialize();

            _stockListener  = new RSIStockTickerListener(_runtime, PERIOD);
            _expressionText = "every tick=StockTick(stockSymbol='" + SYMBOL + "')";
            //_expressionText = "every tick1=StockTick(stockSymbol='GOOG') -> tick2=StockTick(stockSymbol='GOOG')";
            _factory         = _runtime.CompileDeploy(_expressionText).Statements[0];
            _factory.Events += _stockListener.Update;

            var rsiEvent = typeof(RSIEvent).FullName;
            var viewExpr = "select * from " + rsiEvent + ".win:length(1)";

            _rsiListener     = new RSIListener();
            _factory         = _runtime.CompileDeploy(viewExpr).Statements[0];
            _factory.Events += _rsiListener.Update;
            _rsiListener.Reset();
        }
Example #2
0
        public RealtimeSummaryStmt(EPRuntime runtime)
        {
            //
            // Min,Max,Average total latency from the events (difference in time between A and C) over the past 30 minutes.
            // Min,Max,Average latency between events A/B (time stamp of B minus A) and B/C (time stamp of C minus B).
            //
            string stmtTotal = "select min(latencyAC) as minLatencyAC, " +
                               "max(latencyAC) as maxLatencyAC, " +
                               "avg(latencyAC) as avgLatencyAC, " +
                               "min(latencyAB) as minLatencyAB, " +
                               "max(latencyAB) as maxLatencyAB, " +
                               "avg(latencyAB) as avgLatencyAB, " +
                               "min(latencyBC) as minLatencyBC, " +
                               "max(latencyBC) as maxLatencyBC, " +
                               "avg(latencyBC) as avgLatencyBC " +
                               "from CombinedEvent.win:time(30 min)";

            TotalsStatement = runtime.CompileDeploy(stmtTotal).Statements[0];

            //
            // Min,Max,Average latency grouped by (a) customer ID and (b) supplier ID.
            // In other words, metrics on the the latency of the orders coming from each customer and going to each supplier.
            //
            string stmtCustomer = "select customerId," +
                                  "min(latencyAC) as minLatency," +
                                  "max(latencyAC) as maxLatency," +
                                  "avg(latencyAC) as avgLatency " +
                                  "from CombinedEvent.win:time(30 min) " +
                                  "group by customerId";

            CustomerStatement = runtime.CompileDeploy(stmtCustomer).Statements[0];

            string stmtSupplier = "select supplierId," +
                                  "min(latencyAC) as minLatency," +
                                  "max(latencyAC) as maxLatency," +
                                  "avg(latencyAC) as avgLatency " +
                                  "from CombinedEvent.win:time(30 min) " +
                                  "group by supplierId";

            SupplierStatement = runtime.CompileDeploy(stmtSupplier).Statements[0];
        }
Example #3
0
        public static EPStatement Create(EPRuntime runtime)
        {
            // We need to take in events A, B and C and produce a single, combined event
            string stmt = "insert into CombinedEvent(transactionId, customerId, supplierId, latencyAC, latencyBC, latencyAB)" +
                          "select C.TransactionId," +
                          "CustomerId," +
                          "SupplierId," +
                          "C.Timestamp - A.Timestamp," +
                          "C.Timestamp - B.Timestamp," +
                          "B.Timestamp - A.Timestamp " +
                          "from TxnEventA.win:time(30 min) A," +
                          "TxnEventB.win:time(30 min) B," +
                          "TxnEventC.win:time(30 min) C " +
                          "where A.TransactionId = B.TransactionId and B.TransactionId = C.TransactionId";

            return(runtime.CompileDeploy(stmt).Statements[0]);
        }
Example #4
0
        //
        // We need to detect a transaction that did not make it through all three events.
        // In other words, a transaction with events A or B, but not C.
        // Note that, in this case, what we care about is event C.
        // The lack of events A or B could indicate a failure in the event transport and should be ignored.
        // Although the lack of an event C could also be a transport failure, it merits looking into.
        //
        public static EPStatement Create(EPRuntime runtime)
        {
            // The inner table to both A and B is C.
            //
            // The listener will consider old events generated when either A or B leave the window, with
            // a window size for A and B of 30 minutes.
            //
            // The window of C is declared large to ensure the C events don't leave the window before A and B
            // thus generating false alerts, making these obvious via timestamp. Lets keep 1 hour of data for C.
            string stmt = "select * from " +
                          "TxnEventA.win:time(30 min) A " +
                          "full outer join " +
                          "TxnEventC.win:time(1 hour) C on A.TransactionId = C.TransactionId " +
                          "full outer join " +
                          "TxnEventB.win:time(30 min) B on B.TransactionId = C.TransactionId " +
                          "where C.TransactionId is null";

            return(runtime.CompileDeploy(stmt).Statements[0]);
        }
        public DynaLatencySpikeMonitor(LatencyLimit limit)
        {
            Log.Debug("New limit, for operation '" + limit.OperationName +
                      "' and customer '" + limit.CustomerId + "'" +
                      " setting threshold " + limit.LatencyThreshold);

            var filter = "operationName='" + limit.OperationName +
                         "',customerId='" + limit.CustomerId + "'";

            // Alert specific to operation and customer
            _spikeLatencyDeployment = _runtime.CompileDeploy(
                "every alert=" + typeof(OperationMeasurement).FullName +
                "(" + filter + ", latency>" + limit.LatencyThreshold + ")");
            _spikeLatencyAlert         = _spikeLatencyDeployment.Statements[0];
            _spikeLatencyAlert.Events += LogLatencyEvent;

            // Stop pattern when the threshold changes
            var eventName   = typeof(LatencyLimit).FullName;
            var stopPattern = _runtime.DeployStatement(eventName + "(" + filter + ")");

            stopPattern.Events += ((newEvents, oldEvents) => _runtime
                                   .DeploymentService.Undeploy(_spikeLatencyAlert.DeploymentId));
        }