Search in sources :

Example 1 with Profile

use of com.creditease.uav.profiling.spi.Profile in project uavstack by uavorg.

the class ServerEndRespTimeCapHandler method doProfileIPLink.

/**
 * NOTE: as client ip links are generated by runtime invoking, we have to do this in monitor
 *
 * @param context
 * @param appName
 * @param url
 */
private void doProfileIPLink(CaptureContext context, String appId, String url) {
    String clientAddr = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_CLIENTADDR);
    if (StringHelper.isEmpty(clientAddr)) {
        return;
    }
    Profile p = ProfileFactory.instance().getProfile(appId);
    if (p == null) {
        return;
    }
    ProfileContext pc = new StandardProfileContext();
    pc.put(ProfileConstants.PC_ARG_CLIENTADDR, clientAddr);
    String uavClientTag = (String) context.get(CaptureConstants.INFO_APPSERVER_UAVCLIENT_TAG);
    if (!StringHelper.isEmpty(uavClientTag)) {
        pc.put(ProfileConstants.PC_ARG_UAVCLIENT_TAG, uavClientTag);
    }
    String forwardIPLink = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_FORWARDADDR);
    if (!StringHelper.isEmpty(forwardIPLink)) {
        pc.put(ProfileConstants.PC_ARG_IPLNK, forwardIPLink);
    }
    if (!StringHelper.isEmpty(url)) {
        pc.put(ProfileConstants.PC_ARG_IPLINK_TARGETURL, url);
    }
    String userAgent = (String) context.get(CaptureConstants.INFO_APPSERVER_CLIENT_USRAGENT);
    if (!StringHelper.isEmpty(userAgent)) {
        pc.put(ProfileConstants.PC_ARG_IPLINK_USRAGENT, userAgent);
    }
    String proxyhost = (String) context.get(CaptureConstants.INFO_APPSERVER_PROXY_HOST);
    if (!StringHelper.isEmpty(proxyhost)) {
        pc.put(ProfileConstants.PC_ARG_PROXYHOST, proxyhost);
    }
    pc.put(ProfileConstants.PC_ARG_APPID, appId);
    pc.put(ProfileConstants.PC_ARG_SVRHOST, this.serverAddress);
    pc.addPE(ProfileConstants.PROELEM_IPLINK);
    p.doProfiling(pc);
}
Also used : StandardProfileContext(com.creditease.uav.profiling.StandardProfileContext) ProfileContext(com.creditease.uav.profiling.spi.ProfileContext) StandardProfileContext(com.creditease.uav.profiling.StandardProfileContext) Profile(com.creditease.uav.profiling.spi.Profile)

Example 2 with Profile

use of com.creditease.uav.profiling.spi.Profile in project uavstack by uavorg.

the class UAVServerJEEController method doRequest.

@Override
protected void doRequest(HttpServletRequest request, HttpServletResponse response, InterceptContext ic) {
    String action = request.getParameter("action");
    /**
     * ping
     */
    if (action.equalsIgnoreCase("ping")) {
        ServerVendor sv = (UAVServer.ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
        this.writeResponseBody(response, sv.toString(), HttpServletResponse.SC_OK);
    }
    /**
     * setSystemPro: set SystemProperties
     */
    if ("setSystemPro".equalsIgnoreCase(action)) {
        String jsonStr = this.getRequestBodyAsString(request, "utf-8");
        try {
            @SuppressWarnings("unchecked") Map<String, String> params = JSONHelper.toObject(jsonStr, Map.class);
            Map<String, Object> metaMap = new HashMap<String, Object>();
            for (String key : params.keySet()) {
                System.setProperty(key, params.get(key));
                if (UAVMetaDataMgr.SystemMeta.contains(key)) {
                    metaMap.put(key, params.get(key));
                }
            }
            // flush systemMeta to metaData
            UAVServer.instance().getMetaMgr().addMetaData(metaMap);
            this.writeResponseBody(response, "OK", HttpServletResponse.SC_OK);
        } catch (Exception e) {
            this.writeResponseBody(response, "Err", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } else /**
     * getSystemPro
     */
    if (action.equalsIgnoreCase("getSystemPro")) {
        this.writeResponseBody(response, JSONHelper.toString(System.getProperties()), HttpServletResponse.SC_OK);
    } else /**
     * startSupporter: dynamic start supporters
     */
    if ("startSupporter".equalsIgnoreCase(action)) {
        controlSupporters(request, response, true);
    } else /**
     * stopSupporter
     */
    if ("stopSupporter".equalsIgnoreCase(action)) {
        controlSupporters(request, response, false);
    } else /**
     * runSupporter
     */
    if ("runSupporter".equalsIgnoreCase(action)) {
        runSupporter(request, response);
    } else /**
     * dump profile data
     */
    if ("dumpProfile".equalsIgnoreCase(action)) {
        String targetPath = request.getParameter("path");
        if (StringHelper.isEmpty(targetPath)) {
            targetPath = (String) UAVServer.instance().getServerInfo(CaptureConstants.INFO_MOF_METAPATH);
        }
        String dumpFile = targetPath + "/p_" + NetworkHelper.getLocalIP() + "_" + UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_LISTEN_PORT) + ".profile";
        Collection<Profile> profiles = DataObserver.instance().getProfiles();
        StringBuilder sb = new StringBuilder("{");
        for (Profile p : profiles) {
            sb.append("\"" + p.getId() + "\":" + p.getRepository().toJSONString() + ",");
        }
        if (sb.length() > 3) {
            sb = sb.deleteCharAt(sb.length() - 1);
        }
        String data = sb.append("}").toString();
        try {
            IOHelper.writeTxtFile(dumpFile, data, "utf-8", false);
        } catch (IOException e) {
            this.logger.warn("DUMP Profile Fail. ", e);
        }
    }
}
Also used : HashMap(java.util.HashMap) ServerVendor(com.creditease.monitor.UAVServer.ServerVendor) Collection(java.util.Collection) IOException(java.io.IOException) IOException(java.io.IOException) Profile(com.creditease.uav.profiling.spi.Profile)

Example 3 with Profile

use of com.creditease.uav.profiling.spi.Profile in project uavstack by uavorg.

the class ClientRespTimeCapHandler method doProfileClient.

/**
 * do client profiling
 *
 * @param context
 * @param clientRequestURL
 */
private void doProfileClient(CaptureContext context, String clientRequestURL, String appid) {
    Profile p = ProfileFactory.instance().getProfile(appid);
    if (p != null) {
        ProfileContext pc = new StandardProfileContext();
        String action = (String) context.get(CaptureConstants.INFO_CLIENT_REQUEST_ACTION);
        Integer rc = (Integer) context.get(CaptureConstants.INFO_CLIENT_RESPONSECODE);
        String type = (String) context.get(CaptureConstants.INFO_CLIENT_TYPE);
        String server = (String) context.get(CaptureConstants.INFO_CLIENT_TARGETSERVER);
        pc.put(ProfileConstants.PC_ARG_CLIENT_URL, clientRequestURL);
        pc.put(ProfileConstants.PC_ARG_CLIENT_ACTION, action);
        pc.put(ProfileConstants.PC_ARG_CLIENT_RC, rc);
        pc.put(ProfileConstants.PC_ARG_CLIENT_TYPE, type);
        pc.put(ProfileConstants.PC_ARG_CLIENT_TARGETSERVER, server);
        pc.addPE(ProfileConstants.PROELEM_CLIENT);
        p.doProfiling(pc);
    }
}
Also used : StandardProfileContext(com.creditease.uav.profiling.StandardProfileContext) ProfileContext(com.creditease.uav.profiling.spi.ProfileContext) StandardProfileContext(com.creditease.uav.profiling.StandardProfileContext) Profile(com.creditease.uav.profiling.spi.Profile)

Example 4 with Profile

use of com.creditease.uav.profiling.spi.Profile in project uavstack by uavorg.

the class AppProfilingListener method startProfiling.

/**
 * start create the profile and doing profiling on webapp startup
 *
 * @param contextroot
 * @param pf
 * @param webapploader
 * @param context
 */
protected void startProfiling(String contextroot, String basePath, ProfileFactory pf, ProfileContext context) {
    String appid = MonitorServerUtil.getApplicationId(contextroot, basePath);
    /**
     * NOTE: as the internal application, we will not profile it
     */
    if ("com.creditease.uav".equalsIgnoreCase(appid)) {
        return;
    }
    if (this.logger.isLogEnabled()) {
        this.logger.info("Profiling of Application[ " + appid + "] START...");
    }
    String profileId = MonitorServerUtil.getApplicationId(contextroot, basePath);
    Profile p = pf.buildProfile(profileId);
    if (null != p) {
        if (this.logger.isLogEnabled()) {
            this.logger.info("Creating Profile Object of Application[ " + appid + "] DONE");
        }
        DataObserver.instance().installProfile(p);
        if (this.logger.isLogEnabled()) {
            this.logger.info("Profile Object [" + p.getId() + "] of Application[ " + appid + "]  is INSTALLED on data observer");
        }
        /**
         * doing the profiling
         */
        try {
            p.doProfiling(context);
            if (this.logger.isLogEnabled()) {
                this.logger.info("Profiling of Application[ " + appid + "] DONE SUCCESS ");
            }
        } catch (Exception e) {
            this.logger.error("Profiling of Application[ " + appid + "] FAILs ", e);
        }
    } else {
        if (this.logger.isLogEnabled()) {
            this.logger.warn("Profiling of Application[ " + appid + "] FAILs", null);
        }
    }
}
Also used : Profile(com.creditease.uav.profiling.spi.Profile)

Example 5 with Profile

use of com.creditease.uav.profiling.spi.Profile in project uavstack by uavorg.

the class AppProfilingListener method stopProfiling.

/**
 * destory profile and release all resources of the profile
 *
 * @param contextroot
 * @param pf
 * @param webapploader
 */
protected void stopProfiling(String contextroot, String basePath, ProfileFactory pf) {
    String appid = MonitorServerUtil.getApplicationId(contextroot, basePath);
    if (this.logger.isLogEnabled()) {
        this.logger.info("destorying profile of Application[ " + appid + "] START...");
    }
    String profileId = MonitorServerUtil.getApplicationId(contextroot, basePath);
    Profile p = pf.destroyProfile(profileId);
    if (null != p) {
        if (this.logger.isLogEnabled()) {
            this.logger.info("destorying profile of Application[ " + appid + "] END SUCCESS");
        }
        DataObserver.instance().uninstallProfile(p);
        if (this.logger.isLogEnabled()) {
            this.logger.info("profile[" + p.getId() + "] of Application[ " + appid + "]  is UNINSTALLED on data observer");
        }
    } else {
        if (this.logger.isLogEnabled()) {
            this.logger.warn("destorying profile of Application[ " + appid + "]  FAILs", null);
        }
    }
}
Also used : Profile(com.creditease.uav.profiling.spi.Profile)

Aggregations

Profile (com.creditease.uav.profiling.spi.Profile)5 StandardProfileContext (com.creditease.uav.profiling.StandardProfileContext)2 ProfileContext (com.creditease.uav.profiling.spi.ProfileContext)2 ServerVendor (com.creditease.monitor.UAVServer.ServerVendor)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1