Show Table of Contents




3.10. SLA
3.10.1. Monitor
The example located in the
samples/sla/monitor folder demonstrates an approach to provide "Service Level Agreement" monitoring. This example makes uses of the example Switchyard application located in the samples/ordermgmt folder. This example will shows:
- activity event analysis, using the Event Processor Network mechanism, can be used to implement Service Level Agreements
- uses the Complex Event Processing (CEP) based event processor (using Drools Fusion)
- impending or actual SLA violations can be reported for the attention of end users, via
- JMX notifications
- REST service
- to build a custom application to access the analysis results
This example shows a simple Service Level Agreement that checks whether a service response time exceeds expected levels. The CEP rule detects whether a situation of interest has occurred, and if so, creates a
org.overlord.rtgov.analytics.situation.Situation object and initializes it with the appropriate description or severity information, before forwarding it back into the EPN. This results in the "Situation" object being published as a notification on the "Situations" subject.
The CEP rule is:
import org.overlord.rtgov.analytics.service.ResponseTime
import org.overlord.rtgov.analytics.situation.Situation
global org.overlord.rtgov.ep.EPContext epc
declare ResponseTime
@role( event )
end
rule "check for SLA violations"
when
$rt : ResponseTime() from entry-point "ServiceResponseTimes"
then
if ($rt.getAverage() > 200) {
epc.logError("\r\n\r\n**** RESPONSE TIME "+$rt.getAverage()+"ms EXCEEDED SLA FOR "+$rt.getServiceType()+" ****\r\n");
Situation situation=new Situation();
situation.setType("SLA Violation");
situation.setSubject(Situation.createSubject($rt.getServiceType(), $rt.getOperation(),
$rt.getFault()));
situation.setTimestamp(System.currentTimeMillis());
situation.getProperties().putAll($rt.getProperties());
if ($rt.getRequestId() != null) {
situation.getActivityTypeIds().add($rt.getRequestId());
}
if ($rt.getResponseId() != null) {
situation.getActivityTypeIds().add($rt.getResponseId());
}
situation.getContext().addAll($rt.getContext());
String serviceName=$rt.getServiceType();
if (serviceName.startsWith("{")) {
serviceName = javax.xml.namespace.QName.valueOf(serviceName).getLocalPart();
}
if ($rt.getAverage() > 400) {
situation.setDescription(serviceName+" exceeded maximum response time of 400 ms");
situation.setSeverity(Situation.Severity.Critical);
} else if ($rt.getAverage() > 320) {
situation.setDescription(serviceName+" exceeded response time of 320 ms");
situation.setSeverity(Situation.Severity.High);
} else if ($rt.getAverage() > 260) {
situation.setDescription(serviceName+" exceeded response time of 260 ms");
situation.setSeverity(Situation.Severity.Medium);
} else {
situation.setDescription(serviceName+" exceeded response time of 200 ms");
situation.setSeverity(Situation.Severity.Low);
}
epc.handle(situation);
}
end
The "out of the box" active collection configuration is pre-initialized with a collection for the org.overlord.rtgov.analytics.situation.Situation objects, subscribing to the "Situations" subject from the Event Processor Network. Therefore any detected SLA violations will automatically be stored in this collection (accessible via a RESTful service), and reported to the associated JMX notifier.
3.10.1.1. Quickstart Example
The quickstart example in this esection demonstrates how Service Level Agreements can be policed using rules defined in an Event Processor Network, and reporting to end users using the pre-configured "Situations" active collection. The rule used in this example is detecting whether the response time associated with an operation on a service exceeds a particular level. However more complex temporal rules could be defined to identify the latency between any two points in a business transaction flow.
3.10.1.2. Installing the Example
- Start the Switchyard server using the following command from the bin folder:
./standalone.sh -c standalone-full.xml
- Install the example Switchyard application by running the following command from the
${rtgov}/samples/ordermgmtfolder:mvn jboss-as:deploy
- Change to the
${rtgov}/samples/sla/epn and ${rtgov}/samples/sla/monitorfolder and run the following command again:mvn jboss-as:deploy
3.10.1.3. Running the Example
- To demonstrate a Service Level Agreement violation, send the following message to the example Switchyard application at http://localhost:8080/demo-orders/OrderService:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <orders:submitOrder xmlns:orders="urn:switchyard-quickstart-demo:orders:1.0"> <order> <orderId>3</orderId> <itemId>JAM</itemId> <quantity>400</quantity> <customer>Fred</customer> </order> </orders:submitOrder> </soap:Body> </soap:Envelope>The message can be sent using an appropriate SOAP client (for example, SOAP-UI) or by running the test client available with the Switchyard application, by running the following command from the${rtgov}/samples/ordermgmt/appfolder:mvn exec:java -Dreq=order3
The itemId of "JAM" causes a delay to be introduced in the service, resulting in a SLA violation being detected. This violation can be viewed using the following approaches:- REST Service
- JMX Console
3.10.1.3.1. REST Service
Using a suitable REST client, send the following POST to http://localhost:8080/overlord-rtgov/acm/query (using content-type of "application/json", username as admin, and password as overlord):
{
"collection" : "Situations"
}
This will result in the following response:
Figure 3.6. Response

3.10.1.3.2. JMX Console
The Situations active collection source also generates JMX notifications that can be subscribed to using a suitable JMX management application. For example, using JConsole we can view the SLA violation:
Figure 3.7. JMX Console

3.10.1.3.3. Accessing Results Within a Custom Application
Apart from accessing the information via REST or JMX, you may also have more direct access to the active collection results. This section describes the custom application defined in the
${rtgov}/samples/sla/monitor folder.
The following code shows how the custom application initializes access to the relevant active collections:
@Path("/monitor")
@ApplicationScoped
public class SLAMonitor {
private static final String SERVICE_RESPONSE_TIMES = "ServiceResponseTimes";
private static final String SITUATIONS = "Situations";
private static final Logger LOG=Logger.getLogger(SLAMonitor.class.getName());
private ActiveCollectionManager _acmManager=null;
private ActiveList _serviceResponseTime=null;
private ActiveList _situations=null;
/**
* This is the default constructor.
*/
public SLAMonitor() {
try {
_acmManager = ActiveCollectionManagerAccessor.getActiveCollectionManager();
_serviceResponseTime = (ActiveList)
_acmManager.getActiveCollection(SERVICE_RESPONSE_TIMES);
_situations = (ActiveList)
_acmManager.getActiveCollection(SITUATIONS);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Failed to initialize active collection manager", e);
}
}
When the REST request is received (for example, for SLA violations defined as Situations):
@GET
@Path("/situations")
@Produces("application/json")
public java.util.List<Situation> getSituations() {
java.util.List<Situation> ret=new java.util.ArrayList<Situation>();
for (Object obj : _situations) {
if (obj instanceof Situation) {
ret.add((Situation)obj);
}
}
return (ret);
}
To see the SLA violations, send a REST GET request to http://localhost:8080/slamonitor-monitor/monitor/situations . This returns the following information:
Figure 3.8. Response

You can also request the list of response time information from the same custom service, using the URL http://localhost:8080/slamonitor-monitor/monitor/responseTimes?operation=submitOrder:
Figure 3.9. Response

Caution
If no query parameter is provided, then response times for all operations will be returned.
3.10.2. Report
The example located in the
samples/sla/report folder demonstrates how to provide pluggable reports that can access information in the activity store. This example uses the activity information to compile a Service Level Agreement report, highlighting violations above a specified response time.
This example shows:
- how to configure a pluggable report
- how to generate the report via a REST API
This example provides a simple Service Level Agreement report, based on identifying service invocations that exceed a specified maximum response time over an optionally specified averaged duration. If the averaged duration is not specified, then each service invocation is checked to determine if it exceeded the maximum response time. If so, it gets added to the report. If the averaged duration is specified, then when an invocation is detected (that exceeds the max response time), then all other suitable invocations within the specified duration are averaged to determine if the response time overall still exceeds the specified maximum. This is to ensure that periodic spikes are not unnecessarily reported.
It is also possible to optionally specify a business calendar, which can be used to determine the business period in which activities are of interest. If SLA violations occur outside the specified business calendar, then they are not relevant.
The report definition is:
[
{
"name" : "SLAReport",
"generator" : {
"@class" : "org.overlord.rtgov.reports.MVELReportGenerator",
"scriptLocation" : "SLAReport.mvel"
}
}
]
You can find the MVEL based report generator script in the
${rtgov}/samples/sla/report/src/main/resources folder.
Note
Currently the report parameters serviceType, operation and principal are not used.
3.10.2.1. Quickstart Example
The quickstart example in this section demonstrates how report definitions can be deployed to the Runtime Governance infrastructure and invoked to generate a report instance via a REST service.
3.10.2.2. Installing the Example
- Start the Switchyard server using the following command from the bin folder:
./standalone.sh -c standalone-full.xml
- Run the following mvn command from the
${rtgov}/samples/sla/reportfolder:mvn jboss-as:deploy
3.10.2.3. Running the Example
To demonstrate a Service Level Agreement report, you can create relevant activities that can be reported upon. For this, send multiple instances of the following messages to the example Switchyard application at :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<orders:submitOrder xmlns:orders="urn:switchyard-quickstart-demo:orders:1.0">
<order>
<orderId>1</orderId>
<itemId>BUTTER</itemId>
<quantity>100</quantity>
<customer>Fred</customer>
</order>
</orders:submitOrder>
</soap:Body>
</soap:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<orders:submitOrder xmlns:orders="urn:switchyard-quickstart-demo:orders:1.0">
<order>
<orderId>3</orderId>
<itemId>JAM</itemId>
<quantity>100</quantity>
<customer>Fred</customer>
</order>
</orders:submitOrder>
</soap:Body>
</soap:Envelope>
Send the second message few time, as this is the one that results in SLA violations.
The message can be sent using an appropriate SOAP client (for example, SOAP-UI) or by running the test client available with the Switchyard application, by running the following commands from the
${rtgov}/samples/ordermgmt/app folder:
mvn exec:java -Dreq=order1 mvn exec:java -Dreq=order3
To generate a report, send a GET request to the following URL using Basic Authentication with a valid Application Realm username and password:
http://localhost:8080overlordrtgovreportgeneratereport=SLAReport&startDay=1&startMonth=1&startYear=2013&endDay=31&endMonth=12&endYear=2013&maxResponseTime=400&averagedDuration=450
This returns a report with name SLAReport, containing violations that occur within the year 2013. To experiment with the default business calendar, append the following to the end of the URL:
&calendar=DefaultThis also identifies what percentage of the business working period has been impacted by the SLA violations.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.