use of com.creditease.uav.util.LimitLinkedHashMap in project uavstack by uavorg.
the class ClientProfileHandler method doProfiling.
@SuppressWarnings("unchecked")
@Override
public void doProfiling(ProfileElement elem, ProfileContext context) {
if (!ProfileConstants.PROELEM_CLIENT.equals(elem.getElemId())) {
return;
}
String clientURL = (String) context.get(ProfileConstants.PC_ARG_CLIENT_URL);
if (clientURL == null) {
return;
}
long curTime = System.currentTimeMillis();
String type = (String) context.get(ProfileConstants.PC_ARG_CLIENT_TYPE);
ProfileElementInstance pei = null;
String actionPath = null;
// for http://
if (clientURL.indexOf("http://") == 0) {
URI clientTargetURI = null;
try {
clientTargetURI = new URI(clientURL);
} catch (URISyntaxException e) {
return;
}
pei = getTargetURIInst(clientTargetURI, elem);
actionPath = clientTargetURI.getPath();
} else // for none jdbc /redis /mongo
{
pei = elem.getInstance(clientURL);
actionPath = "ap";
}
pei.setValue("ts", curTime);
String ctype = (String) pei.getValues().get("type");
if (ctype == null) {
pei.setValue("type", type);
} else {
if (ctype.indexOf(type) == -1) {
pei.setValue("type", ctype + "," + type);
}
}
/**
* NOTE: sometimes the ngnix or proxys or tomcat will tell us the server type in reponse header
*/
String server = (String) context.get(ProfileConstants.PC_ARG_CLIENT_TARGETSERVER);
if (!StringHelper.isEmpty(server)) {
pei.setValue("svr", server);
}
Map<String, Object> urls = (Map<String, Object>) pei.getValues().get("urls");
if (urls == null) {
int limit = DataConvertHelper.toInt(System.getProperty("com.creditease.uav.profile.eleminst.client.urls.limit"), 100);
urls = new LimitLinkedHashMap<String, Object>(limit);
pei.setValue("urls", urls);
}
Map<String, Object> urlAttrs = (Map<String, Object>) urls.get(actionPath);
if (urlAttrs == null) {
urlAttrs = new HashMap<String, Object>();
urls.put(actionPath, urlAttrs);
}
urlAttrs.put("ts", curTime);
String action = (String) context.get(ProfileConstants.PC_ARG_CLIENT_ACTION);
Integer rc = (Integer) context.get(ProfileConstants.PC_ARG_CLIENT_RC);
if (rc == 1) {
urlAttrs.put(MonitorServerUtil.getActionTag(action), curTime);
} else if (rc == -1) {
urlAttrs.put(MonitorServerUtil.getActionErrorTag(action), curTime);
}
}
Aggregations