请求指标扩展
某些应用程序可能需要请求指标流中的其他检测点。例如,您可能需要了解独特的后端系统的响应时间,如以下调用图中所示:
HTTP 请求/交易/方案 ------------------------------> 172 ms
Servlet/交易/方案 --------------------------------> 130 ms
至唯一后端系统的 Servlet/调用 -------------------------->38 ms
当跟踪系统中的每个请求流时,请求指标使用“标记”或“相关因子”。要使用此检测来创建上述调用图,您必须插入该请求流并行出适当的应用程序响应测量 (ARM) API,以使 ARM 代理程序收集数据并使 ARM 供应商创建调用图。
请求指标为您声明关联服务 API 以插入请求流。以下示例是某个典型流,它可能后跟检测应用程序以插入请求指标流。
- 创建运行各种检测调用(如启动或停止)的新 ArmTransaction 对象。在插入请求指标流之前,关联服务 Arm 包装器 (PmiRmArmTx) 包括此对象。
- 使用适当的 ArmCorrelator 对象填充 ArmTransaction 对象。此对象包括实际的 ARM 相关因子字节。
- 运行 ArmTransaction 对象的启动方法,标记检测方法开始。
- 使用 PmiRmArmTxFactory 类的静态方法将 PmiRmArmTx 对象实例化,并使用上述 ArmTransaction 对象来填充 PmiRmArmTx 对象。
- 通过使用 PmiRmArmStack 类的公开方法将上述 PmiRmArmTx 对象推送到关联服务堆栈,将该对象传递到关联服务。
- 执行需要通过正在检测的方法来完成的任务。关联服务按需处理以下 ArmTransaction 对象,最终形成事务次数的调用图视图。
- 在检测方法结束时,请使用 PmiRmArmStack 类的声明方法从关联服务访问 PmiRmArmTx 对象、访问 ArmTransaction 对象并执行停止以表明事务结束。
将 ARM API 与作为 Servlet 检测的一部分的相关服务配合使用时,请参考此信息。
应该依照实现提供程序提供的安装指示信息安装 arm40 二进制数。一旦完成此操作,请重新启动服务器。这会引起在 SystemOut.log 文件中生成跟踪记录,以表明适当 ARM 实现的实例化。以下示例说明与作为 Servlet 检测的部件的相关服务协同使用 ARM API 的某种典型工作流程。
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)
logger.warning("MSG_KEY_01");
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;
}
}
注: 本主题引用了一个或多个应用程序服务器日志文件。作为另一种建议采用的方法,您可以在分布式系统和 IBM® i 系统上配置服务器以使用高性能可扩展日志记录 (HPEL) 记录和跟踪基础结构,而不使用 SystemOut.log、SystemErr.log、trace.log 和 activity.log 文件。您还可以将 HPEL 与本机 z/OS® 日志记录设施结合使用。如果要使用 HPEL,那么可从服务器概要文件
bin 目录使用 LogViewer 命令行工具来访问所有日志和跟踪信息。有关使用
HPEL 的更多信息,请参阅有关使用 HPEL 对应用程序进行故障诊断的信息。
存在几种使用 PmiRmArmStack 的可能方案。此示例会显示这样一种方案,在其中代码访问堆栈上现有的 PmiRmArmTx、抽取相关因子和调用阻塞和取消阻塞的程序。当按照不支持的协议发送相关因子时,这是典型方案。在此方案中,Arm 事务已在堆栈上。
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 }