In my last post I introduced BusinessEvents 6 new feature supporting Application Metrics and InfluxDB metric stores.
In this article I will quickly demonstrate how this new feature can be utilised to generate processing rate metrics within your BusinessEvents 6 Application.
We start by defining two Concepts: Counters and Rates and two Simple Events: ResetCountersEvent and UpdateRateEvent .
For those unfamiliar with BusinessEvents Concepts allow us to hold contextual state within BusinessEvents and allow us to not only store last-known state but also historical state too.
Simple Events model the properties that BusinessEvents consumes and are used to trigger our Rule logic using the RETE algorithm built-in to TIBCO BusinessEvents.
The Counter Concept will be used as an incremental counter of the number of Events processed within a given period. The Rates Concept will be used to hold the total number of events processed within a given period.
For both Concepts we will provide two properties: name and value. For each rate we want to capture we can refer to the Concept instance by name. The value will be our counter property.
The Counters Concept value property needs to be incremented whenever a particular activity occurs, in this instance i’m going to have a Rule UpdateCounter execute when an Event occurs e.g. Customer Order Created event.
We will also define a Startup Rule Function that will be called by the BusinessEvents when first starting to initialise both Counters and Rates Concepts values to 0.
BusinessEvents uses a declarative model for the execution of Rules. Rules are executed when a condition is met e.g. an Event arriving or contextual state being modified.
We also need rule to execute that updates the Rate Concept to the latest value stored in our Counters Concept. However this rule needs to execute based on a Timer interval occurring.
In order to calculate the rate we need a Time Event that will trigger at a set interval. With BusinessEvents we have a built in timer mechanism that we can configure to fire at set intervals of say once per minute.
When the ResetCountersTimer Timer Event executes we will have a TimerExpiredRule execute. The TimerExpiredRule will assert two Simple Events in to the RETE network of BusinessEvents that we will use to trigger rules that will:
- Reset the Counter Concept properties ‘value’ back to 0.
- Set the Rate Concept properties ‘value’ to the last value held in the Counter Concept i.e. the actual rate recorded.
Here’s our TimerExpiredRule that will trigger the two rules based on the ResetCountersTimer Time Event occurring:
As you can see in the above Rule Actions block, we are using the ability to assert Simple Events in to the RETE network of the BusinessEvents engine. These events will trigger the actual resetting and updating the Rates and Counters Concepts.
We need a rule to reset the Counters Concept value property back to 0. This rule is executed by the ResetCountersTimer Event which is asserted by TimerExpiredRule using the following Catalog Functions:
Event.assertEvent(Events.ResetCountersEvent.ResetCountersEvent(null, null,”inbound”));
As well as resetting the Counter Concept’s value property we need a rule to set the Rate Concept’s value property.
Like the ResetCounter Rule, the UpdateRates Rule is executed when the UpdateRateEvent is asserted:
Event.assertEvent(Events.UpdateRateEvent.UpdateRateEvent(null,null,”inbound”));
Testing our application we can see that our Timer firing interval is 1 minute and the Rate recorded by our Rates Concept is 0:
Firing in a request we can see that the UpdateCounter Rule is fired and the Counters Concept value property as 1:
We can see the TimerExpiredRule and UpdateRates Rules firing based on the 1 minute timer interval being hit. Here the UpdateRates Rule logs the value of the Rates Concepts value property is 1:
If we wait a further minute without any requests we can see the Rate returns to 0:
Ok, lets generate some further load and see what happens:
$ repeat 1000 ./loadgen.sh
After configuring the Metrics Store and Entity within the CDD we can quickly switch to Grafana and visualise our rate metric
Hope you find this article useful.