Certain applications might require additional instrumentation points within the request metrics flow. For example, you might want to understand the response time to a unique back-end system as seen in the following call graph:
HTTP request /trade/scenario ------------------------------> 172 ms Servlet/trade/scenario --------------------------------> 130 ms Servlet/call to unique back-end system -------------------------->38 ms
Request metrics uses a "token" or "correlator" when tracing the flow of each request through the system. To create the call graph above with this instrumentation, you must plug into that flow of the request and issue the appropriate Application Response Measurement (ARM) API for an ARM agent to collect the data and for the ARM vendor to create the call graph.
The arm40 binaries should be installed in accordance with the installation instructions supplied by the implementation provider. Once this is done, restart the server. This causes trace records to be generated in the SystemOut.log file indicating the instantiation of the appropriate ARM implementation. The following example illustrates one of the typical workflows of using the ARM API in conjunction with the correlation service as part of a servlet instrumentation:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PmiRmArmTx artrax =
// The factory detects the currently active ARM implementation (specified by user through
// admin console) and instantiates an appropriate ARM wrapper object
PmiRmArmTxFactory.createPmiRmArmTx();
ArmTransaction at = newArmTx();
if (null == at)
out.println("Got a null ArmTransaction");
ArmCorrelator arc = newArmCorr();
at.start(arc);
try {
artrax.setArmTransaction(at);
PmiRmArmStack.pushTransaction(artrax);
} catch (Exception e) {
System.out.println("Caught 1 exception" + e);
}
PmiRmArmTx atxwrp = PmiRmArmStack.peekTransaction();
if (atxwrp == null)
out.println("Armtransaction is null");
//getArmType
try {
out.println("ARMTYPE is"+ PmiRmArmTx.getARMType());
} catch (Exception e) {
out.println(e);
}
//getting correlator bytes
try {
if (null == atxwrp.getCorrelatorBytes())
out.println("Got a null Correlator");
} catch (Exception e) {
out.println(e);
}
//blocked/unblocked
long blkid = 0;
try {
out.println(blkid = atxwrp.blocked());
} catch (Exception e) {
out.println(e);
}
try {
out.println(atxwrp.unblocked(blkid));
} catch (Exception e) {
out.println(e);
}
try {
atxwrp = PmiRmArmStack.popTransaction();
ArmTransaction art = (ArmTransaction) atxwrp.getArmTransaction();
art.stop(ArmConstants.STATUS_GOOD);
} catch (Exception e) {
out.println(e);
}
}
private ArmTransaction newArmTx() {
ArmTransactionFactory txFactory = null;
try {
String sWasName = "WebSphere";
String appName = "t23xpimage/t23xpimage/server1";
String sCellName = appName.substring(0, appName.indexOf("/"));
String sNodeInstance =
appName.substring(appName.indexOf("/") + 1, appName.length());
sNodeInstance = sNodeInstance.replace('/', '.');
txFactory = (ArmTransactionFactory)
newObjectInstance("org.opengroup.arm40.sdk.ArmTransactionFactoryImpl");
ArmApplication app = null; // 149297
ArmApplicationDefinition appDef = null; //LIDB3207
appDef = txFactory.newArmApplicationDefinition(sWasName, null, null);
app = txFactory.newArmApplication(appDef, sCellName, sNodeInstance, null);
String[] idnames = { "request_type" };
String[] idvalues = { "URI" };
String[] ctxnames = { "URI" };
ArmIdentityPropertiesTransaction props =
txFactory.newArmIdentityPropertiesTransaction(
idnames,
idvalues,
ctxnames,
null);
ArmTransactionDefinition atd =
txFactory.newArmTransactionDefinition(
appDef,
"URI",
props,
(ArmID) null);
ArmTransaction at = txFactory.newArmTransaction(app, atd);
return at;
} catch (Exception e) {
System.out.println(e);
return null;
}
}
private ArmCorrelator newArmCorr() {
ArmTransactionFactory txFactory = null;
try {
String sWasName = "WebSphere";
String appName = "t23xpimage/t23xpimage/server1";
txFactory =
(ArmTransactionFactory) newObjectInstance("org.opengroup.arm40.sdk.ArmTransactionFactoryImpl");
ArmCorrelator arc =txFactory.newArmCorrelator(
PmiRmArmStack.peekTransaction().getCorrelatorBytes());
return arc;
} catch (Exception e) {
System.out.println(e);
return null;
}
}
There are several potential scenarios for using the PmiRmArmStack. This example shows a scenario where code accesses an existing PmiRmArmTx on the stack, extracts the correlator, and calls blocked and unblocked. This is a typical scenario when sending a correlator along an unsupported protocol. In this scenario, the Arm transaction is already on the stack.
1 PmiRmArmTx artrax =
2 PmiRmArmStack.peekTransaction();
3 if( artrax != null )
4 {
5 try
6 {
7 byte[] cbytes = artrax.getCorrelatorBytes();
8 stuffBytesIntoOutboundMessage( msg, cbytes);
9 long blockedId = 0;
10 try
11 {
12 blockedId = artrax.blocked();
13 }
14 catch( NoSuchMethodException nsme )
15 {
16 // must not be running ARM4 or eWLM
17 }
18 sendMsg( msg );
19 try
20 {
21 artrax.blocked( blockedId );
22 }
23 catch( NoSuchMethodException nsme )
24 {
25 // must not be running ARM4 or eWLM
26 }
27
28 }
29 catch( Exception e )
30 {
31 report a problem;
32 }
33 }