Search in sources :

Example 1 with LimitLinkedHashMap

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);
    }
}
Also used : ProfileElementInstance(com.creditease.uav.profiling.spi.ProfileElementInstance) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HashMap(java.util.HashMap) LimitLinkedHashMap(com.creditease.uav.util.LimitLinkedHashMap) Map(java.util.Map)

Aggregations

ProfileElementInstance (com.creditease.uav.profiling.spi.ProfileElementInstance)1 LimitLinkedHashMap (com.creditease.uav.util.LimitLinkedHashMap)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1