New string within Siddhi query expression

335 views Asked by At

I am trying to convert the following expression in natural language to an execution plan in WSO2 CEP.

If the average load of one of the pairs {CPU load, memory load}, {CPU load, storage load}, or {memory load, storage load} associated to a service is greater than or equal to 99%, then send an alert.

First, I have specified the following execution streams:

define stream avgCpuLoadStream (service string, avgCpuLoad double);
define stream avgMemoryLoadStream (service string, avgMemoryLoad double);
define stream avgStorageLoadStream (service string, avgStorageLoad double);
define stream alertStream (service string, cause string);

Then, I have specified the following execution plan:

<?xml version="1.0" encoding="UTF-8"?>
<executionPlan name="alertPlan" statistics="enable" trace="enable" xmlns="http://wso2.org/carbon/eventprocessor">
  <description/>
  <siddhiConfiguration>
    <property name="siddhi.persistence.snapshot.time.interval.minutes">0</property>
    <property name="siddhi.enable.distributed.processing">false</property>
  </siddhiConfiguration>
  <importedStreams>
    <stream as="avgCpuLoadStream" name="avgCpuLoadStream" version="1.0.0"/>
    <stream as="avgMemoryLoadStream" name="avgMemoryLoadStream" version="1.0.0"/>
    <stream as="avgStorageLoadStream" name="avgStorageLoadStream" version="1.0.0"/>
  </importedStreams>
  <queryExpressions><![CDATA[
from avgCpuLoadStream[avgCpuLoad >= 99] as c
join avgMemoryLoadStream[avgMemoryLoad >= 99] as m on c.service == m.service
select c.service
insert into alertStream;

from avgCpuLoadStream[avgCpuLoad >= 99] as c
join avgStorageLoadStream[avgStorageLoad >= 99] as s on c.service == s.service
select c.service
insert into alertStream;

from avgMemoryLoadStream[avgMemoryLoad >= 99] as m
join avgStorageLoadStream[avgStorageLoad >= 99] as s on m.service == s.service
select m.service
insert into alertStream;
]]></queryExpressions>
  <exportedStreams>
    <stream name="alertStream" valueOf="alertStream" version="1.0.0"/>
  </exportedStreams>
</executionPlan>

This execution plan sends an alert on a service, but it does not send the cause of the alert. Would it be possible in Siddhi to create a new string within the query expression for this purpose? Along the lines of:

from avgCpuLoadStream[avgCpuLoad >= 99] as c
join avgMemoryLoadStream[avgMemoryLoad >= 99] as m on c.service == m.service
select c.service, "CPU and memory overload" as cause
insert into alertStream;

If not, could you suggest an alternative solution?

Best regards from Oslo,

Alessandro

2

There are 2 answers

0
Rajeev Sampath On BEST ANSWER

Yes, you can simply add the new string with single quotes as follows:

from avgCpuLoadStream[avgCpuLoad >= 99] as c
join avgMemoryLoadStream[avgMemoryLoad >= 99] as m on c.service == m.service
select c.service, 'CPU and memory overload' as cause
insert into alertStream;
0
Kacu On

You can create custom function in CEP, which returns string.

For example:

from avgCpuLoadStream[avgCpuLoad >= 99] as c
join avgMemoryLoadStream[avgMemoryLoad >= 99] as m on c.service == m.service
select c.service, customFunction:alert() as cause
insert into alertStream;

This solution is so naive, but it works.