通过Java程序获取Dynatrace数据
“dynaTrace Ajax是一个详细的底层追踪工具,它不仅可以显示所有请求和文件在网络中传输的时间,还会记录浏览器Render、CPU消耗、JavaScript解析和运行情况等详细的信息,而这些也只是dynaTrace Ajax的冰山一角。 ”——Stoyan Stefanov
showslow平台同样采集了dynatrace的数据,所以做为kelude平台前端页面测试组件,同样要支持dynatrace数据的获取,该代码由云晰同学编写维护:
public void execute(HttpServletRequest request,Context context)throws IOException, JSONException{
String str=(String)request.getAttribute(“dynatraceJson”);
JSONObject jsonObject =JSONObject.fromObject(str);
try {
if ((null!=str) && (null!=jsonObject.getString(“url”)) && null!=jsonObject.getString(“ranks”)
&& null!=jsonObject.getString(“rank”) )
{
Integer urlId = frontServiceManager.getUrlId(jsonObject.getString(“url”));
if (urlId > 0){
JSONObject ranksObject = JSONObject.fromObject(jsonObject.getString(“ranks”));
DynatraceDO dynatraceDO = new DynatraceDO();
String version=jsonObject.containsKey(“version”)?jsonObject.getString(“version”):null;
dynatraceDO.setVersion(version);
dynatraceDO.setUrlId(urlId);
dynatraceDO.setRank(getJsonValue(jsonObject,”rank”,null,1));
dynatraceDO.setCache(getJsonValue(ranksObject,”cache”,”rank”,2));
dynatraceDO.setNet(getJsonValue(ranksObject,”net”,”rank”,2));
dynatraceDO.setServer(getJsonValue(ranksObject,”server”,”rank”,2));
dynatraceDO.setJs(getJsonValue(ranksObject,”js”,”rank”,2));
dynatraceDO.setTimetoimpression(getJsonValue(jsonObject,”timetoimpression”,null,1));
dynatraceDO.setTimetoonload(getJsonValue(jsonObject,”timetoonload”,null,1));
dynatraceDO.setTimetofullload(getJsonValue(jsonObject,”timetofullload”,null,1));
dynatraceDO.setReqnumber(getJsonValue(jsonObject,”reqnumber”,null,1));
dynatraceDO.setXhrnumber(getJsonValue(jsonObject,”xhrnumber”,null,1));
dynatraceDO.setPagesize(getJsonValue(jsonObject,”pagesize”,null,1));
dynatraceDO.setCachablesize(getJsonValue(jsonObject,”cachablesize”,null,1));
dynatraceDO.setNoncachablesize(getJsonValue(jsonObject,”noncachablesize”,null,1));
dynatraceDO.setTimeonnetwork(getJsonValue(jsonObject,”timeonnetwork”,null,1));
dynatraceDO.setTimeinjs(getJsonValue(jsonObject,”timeinjs”,null,1));
dynatraceDO.setTimeinrendering(getJsonValue(jsonObject,”timeinrendering”,null,1));
dynatraceDO.setTimeonserver(getJsonValue(jsonObject,”timeonserver”,null,1));
dynatraceDO.setTimeonclient(getJsonValue(jsonObject,”timeonclient”,null,1));
dynatraceDO.setDetails(str);
if(autoURLManager.isKelude(jsonObject.getString(“url”))) {
ProjectUrlsDO projectUrlsDO= new ProjectUrlsDO();
projectUrlsDO.setProjectId(18460);
projectUrlsDO.setUrlId(urlId);
projectUrlsDO.setScenarioName(urlId.toString());
projectUrlsDO.setStatus(1);
if (null != frontServiceManager.getProjectUrls(projectUrlsDO))
frontServiceManager.updateProjectUrls(projectUrlsDO);
else
frontServiceManager.insertProjectUrls(projectUrlsDO);
} else if (autoURLManager.isURLExist(jsonObject.getString(“url”), “20650″)) {
ProjectUrlsDO projectUrlsDO= new ProjectUrlsDO();
projectUrlsDO.setProjectId(20650);
projectUrlsDO.setUrlId(urlId);
projectUrlsDO.setScenarioName(urlId.toString());
projectUrlsDO.setStatus(1);
if (null != frontServiceManager.getProjectUrls(projectUrlsDO))
frontServiceManager.updateProjectUrls(projectUrlsDO);
else
frontServiceManager.insertProjectUrls(projectUrlsDO);
}
Integer dynatraceId = frontServiceManager.insertDynatrace(dynatraceDO);
if (dynatraceId > 0){
frontServiceManager.updateUrlAggregates(urlId, dynatraceId, 3);
logger.warn(“Success received Dynatrace Data! postdata:”+str+” IP:”+getRemortIP(request));
}
}
}else{
//papResponse.setFailed(“接收Dynatrace数据失败”);
logger.error(“Failed received Yslow data! postdata:”+str+” IP:”+getRemortIP(request));
}
} catch (Exception e) {
e.printStackTrace();
}finally{
}
备注:在获取dynatrace数据时,需要考虑各字段为空的情况,修改dynatrace上传的方式为:
修改Dynatrace执行文件目录下的配置文件,dtajax.ini,添加如下配置:
-Dcom.dynatrace.diagnostics.ajax.beacon.uploadurl=http://kelude.taobao.net/perf/front/dynatrace.do
-Dcom.dynatrace.diagnostics.ajax.beacon.portalurl=http://kelude.taobao.net/perf/front/frontQuery.htm
云帅(顾永刚)
淘宝(中国)软件有限公司 技术质量部-测试平台与发展-压测工具