Monitoring Realtime Traffic
This sample demonstrates the real-time analytics features of WSO2 BAM, by using the integrated WSO2 CEP features. Events generated from the <PRODUCT_HOME/samples/rt-traffic/
sample, which is shipped with the product are sent to WSO2 BAM through a created event stream. These events are processed using the WSO2 CEP features, which are embedded inside WSO2 BAM, and then are displayed graphically using the Realtime Traffic Monitoring Toolbox of WSO2 BAM.
Creating an event stream
Follow the steps below to create a new event stream.
- Log in to the WSO2 BAM management console.
- Click Main, and then click Event Streams.
- Click Add Event Stream.
- Enter
org.wso2.sample.rt.traffic
for Event Stream Name , and enter1.0.0
for Event Stream Version. - Enter the following values for Payload Data Attributes under Stream Attributes and click Add.
- Attribute Name -
entry
- Attribute Type -
string
- Attribute Name -
- Click Add Event Stream.
- Select Default WSO2Event Builder in the message that pops up as shown in the below diagram, and click OK.
Creating HTTP event output adaptor
Follow the steps below to create a HTTP event output adaptor.
- In the BAM management console click Configure, and then click Output Event Adaptors.
- Click Add Output Event Adaptor.
- Enter
HTTP
for Event Adaptor Name and selecthttp
for Event Adaptor Type. - Click Add Event Adaptor.
Creating the execution plan
Follow the steps below to create a new execution plan.
- In the BAM management console click Main, and then click Execution Plans.
- Click Add Execution Plan.
- Enter
rt_traffic_plan
for Execution Plan Name. - Under Import Stream select
org.wso2.sample.rt.traffic
for Import Stream, and entertraffic
for As. - Click Import.
- Enter the following query expression in the provided space:
from traffic#window.time(1 sec) select count(entry) as entryCount insert into traffic_out;
- Under Export Stream, enter
traffic_out
for Value of. - Select
Create Stream Definition
for StreamId.Creating the stream definition
- Enter
traffic_out
for Event Stream Name, and1.0.0
for Event Stream Version. - Click Add Event Stream.
Select Custom Event Formatter from the message that pops up, and click OK.
Creating the Custom Event Formatter
- Enter the following values to create a new event formatter:
- Event Formatter Name -
rt_traffic_formatter
- Stream Attributes
-
entryCount long
- Output Event Adaptor Name -
HTTP
- URL -
https://localhost:9443/message_store?type=RT_SAMPLE_STATS
- Username -
admin
- Password -
admin
- Output Event Type -
text
- Event Formatter Name -
- Click Advanced, and type
{{entryCount}}
in the space provided under Output Mapping Content. - Click Add Event Formatter.
- Under Export Stream, enter
traffic_out
for Value of, and selecttraffic_out:1.0.0
for StreamId, and click Add. - Click Add Execution Plan and select Yes in the message, which pops up.
Installing the toolbox
Follow the steps below to install the Realtime Traffic Monitoring Toolbox.
- In the BAM management console click Main, and then click Add under BAM Toolbox menu.
- Select
Realtime Traffic Monitoring Toolbox
from the list under Basic ToolBox. - Click Install.
Publishing data to WSO2 BAM
Follow the steps below to run the sample to execute a data publisher, and send data to WSO2 BAM.
Navigate to
<BAM_HOME>/samples/rt-traffic/
directory using the command line console and execute the following command:ant
This will start executing a data publisher, which will publish data continuously at a random rate to WSO2 BAM.Navigate to
https://<HOST>:9443/bamdashboards/rt_traffic/stats.jag
using your web browser.<HOST>
must be the exact host, on which the server is started up. Replacing it withlocalhost
may not work, because of browser cross domain limitations.You will see a line graph being updated in real-time to show the frequency of the messages being published at that time as follows.