Search in sources :

Example 11 with ProfileElementInstance

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

the class DubboProfileHandler method doProfiling.

@SuppressWarnings("unchecked")
@Override
public void doProfiling(ProfileElement elem, ProfileContext context) {
    UAVServer.ServerVendor sv = (UAVServer.ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
    // only support JEE Application, not support MSCP Application
    if (sv == UAVServer.ServerVendor.MSCP) {
        return;
    }
    if (!ProfileConstants.PROELEM_COMPONENT.equals(elem.getElemId())) {
        return;
    }
    InterceptContext ic = context.get(InterceptContext.class);
    if (ic == null) {
        this.logger.warn("Profile:Annotation FAILs as No InterceptContext available", null);
        return;
    }
    /**
     * 1.get webappclassloader
     */
    ClassLoader webappclsLoader = (ClassLoader) ic.get(InterceptConstants.WEBAPPLOADER);
    if (null == webappclsLoader) {
        this.logger.warn("Profile:JARS FAILs as No webappclsLoader available", null);
        return;
    }
    Map<String, DubboServiceProfileInfo> list = (Map<String, DubboServiceProfileInfo>) ic.get(HookConstants.DUBBO_PROFILE_LIST);
    if (list == null) {
        return;
    }
    // set the instance id = simple name of the annotation class
    ProfileElementInstance inst = elem.getInstance("com.alibaba.dubbo.config.spring.ServiceBean");
    for (String servicekey : list.keySet()) {
        DubboServiceProfileInfo dspi = list.get(servicekey);
        Map<String, Object> info = new LinkedHashMap<String, Object>();
        // get service class & dubbo application id
        String serviceClass = dspi.getServiceClass();
        info.put("dubboAppId", dspi.getDbAppId());
        info.put("group", dspi.getGroup());
        info.put("version", dspi.getVersion());
        info.put("servcls", serviceClass);
        info.put("servimplcls", dspi.getServiceImplClass());
        // get protocols
        Map<String, Object> protocols = new LinkedHashMap<String, Object>();
        info.put("protocols", protocols);
        for (DubboServiceProfileInfo.Protocol pro : dspi.getProtocols()) {
            Map<String, Object> pAttrs = new LinkedHashMap<String, Object>();
            addProtocolAttr(pAttrs, "port", pro.getPort());
            addProtocolAttr(pAttrs, "path", pro.getContextpath());
            addProtocolAttr(pAttrs, "ser", pro.getSerialization());
            addProtocolAttr(pAttrs, "char", pro.getCharset());
            protocols.put(pro.getpName(), pAttrs);
        }
        // get methods
        try {
            Class<?> serviceClassI = webappclsLoader.loadClass(serviceClass);
            ComponentProfileHandler.getMethodInfo(serviceClassI, info);
        } catch (ClassNotFoundException e) {
            continue;
        }
        inst.setValue(servicekey, info);
    }
}
Also used : ProfileElementInstance(com.creditease.uav.profiling.spi.ProfileElementInstance) UAVServer(com.creditease.monitor.UAVServer) DubboServiceProfileInfo(com.creditease.uav.profiling.handlers.dubbo.DubboServiceProfileInfo) LinkedHashMap(java.util.LinkedHashMap) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 12 with ProfileElementInstance

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

the class IPLinkProfileHandler method doProfiling.

@Override
public void doProfiling(ProfileElement elem, ProfileContext context) {
    if (!ProfileConstants.PROELEM_IPLINK.equals(elem.getElemId())) {
        return;
    }
    /**
     * step 1:check if the request is from a browser(human) or an application
     */
    String clientAddr = (String) context.get(ProfileConstants.PC_ARG_CLIENTADDR);
    // in case the wizard thing
    if (clientAddr == null) {
        return;
    }
    String usrAgent = (String) context.get(ProfileConstants.PC_ARG_IPLINK_USRAGENT);
    clientAddr = MonitorServerUtil.getLocalHostToIP(clientAddr);
    String uavClientTag = (String) context.get(ProfileConstants.PC_ARG_UAVCLIENT_TAG);
    String ipLink = (String) context.get(ProfileConstants.PC_ARG_IPLNK);
    String proxyHost = (String) context.get(ProfileConstants.PC_ARG_PROXYHOST);
    String proxyAddress = (proxyHost == null) ? clientAddr : MonitorServerUtil.getLocalHostToIP(proxyHost);
    // proxyAddress = MonitorServerUtil.tryGetIPbyDNS(proxyAddress);
    boolean isFromHttpProxy = (StringHelper.isEmpty(ipLink)) ? false : true;
    boolean isFromBrowser = MonitorServerUtil.isFromBrowser(usrAgent);
    long curTime = System.currentTimeMillis();
    String ipLinkKey = "";
    String realClientIP = null;
    // User + Proxy
    if (isFromBrowser == true && isFromHttpProxy == true) {
        realClientIP = MonitorServerUtil.getClientIP(clientAddr, ipLink);
        realClientIP = "user://" + realClientIP;
        // proxy ip address
        ipLinkKey = "proxy://" + proxyAddress;
    } else // User
    if (isFromBrowser == true && isFromHttpProxy == false) {
        realClientIP = "user://" + clientAddr;
        String appid = (String) context.get(ProfileConstants.PC_ARG_APPID);
        String svrhost = (String) context.get(ProfileConstants.PC_ARG_SVRHOST);
        // client ip
        ipLinkKey = "browser://" + svrhost + "/" + appid;
    } else // App + Proxy
    if (isFromBrowser == false && isFromHttpProxy == true) {
        realClientIP = MonitorServerUtil.getClientIP(clientAddr, ipLink);
        realClientIP = "app://" + realClientIP;
        // if there UAV-Client-Src, use it instead of IP address
        realClientIP = (uavClientTag == null) ? realClientIP : uavClientTag;
        // proxy ip address
        ipLinkKey = "proxy://" + proxyAddress;
    } else // App
    if (isFromBrowser == false && isFromHttpProxy == false) {
        clientAddr = "app://" + clientAddr;
        // if there UAV-Client-Src, use it instead of IP address
        ipLinkKey = (uavClientTag == null) ? clientAddr : uavClientTag;
    }
    /**
     * step 1: tracking ip link
     */
    ProfileElementInstance pei = elem.getInstance(ipLinkKey);
    pei.setValue("ts", curTime);
    /**
     * step 2: see if should exclud some url, such as js, css, image as they are the part of page url NOTE: but
     * still we record this access to app page, but the timstamp may be the last one(js,css,image), they all go to
     * app page
     */
    getAccessTargetInfo(context, curTime, pei);
    /**
     * step 3: only work for those requests for http proxy
     */
    getClientInfo(curTime, pei, realClientIP);
}
Also used : ProfileElementInstance(com.creditease.uav.profiling.spi.ProfileElementInstance)

Example 13 with ProfileElementInstance

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

the class JarProfileHandler method doProfiling.

@Override
public void doProfiling(ProfileElement pe, ProfileContext context) {
    /**
     * handler jars
     */
    if (!ProfileConstants.PROELEM_JARS.equals(pe.getElemId())) {
        return;
    }
    InterceptContext ic = context.get(InterceptContext.class);
    if (ic == null) {
        this.logger.warn("Profile:JARS FAILs as No InterceptContext available", null);
        return;
    }
    ClassLoader webappclsLoader = (ClassLoader) ic.get(InterceptConstants.WEBAPPLOADER);
    if (null == webappclsLoader) {
        this.logger.warn("Profile:JARS FAILs as No webappclsLoader available", null);
        return;
    }
    ProfileElementInstance pei = pe.getInstance(ProfileConstants.PEI_LIB);
    if (!URLClassLoader.class.isAssignableFrom(webappclsLoader.getClass())) {
        this.logger.warn("Profile:JARS FAILs as the webappclassloader is not a URLClassloader", null);
        return;
    }
    URL[] urls = ((URLClassLoader) webappclsLoader).getURLs();
    if (urls == null) {
        this.logger.warn("Profile:JARS FAILs as No JAR URLs from webappclassloader", null);
        return;
    }
    for (URL url : urls) {
        String path = url.getPath();
        String[] pinfo = path.split("/");
        pei.setValue(pinfo[pinfo.length - 1], url.toString());
    }
    /**
     * confirm there is update
     */
    pe.getRepository().setUpdate(true);
}
Also used : ProfileElementInstance(com.creditease.uav.profiling.spi.ProfileElementInstance) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL)

Aggregations

ProfileElementInstance (com.creditease.uav.profiling.spi.ProfileElementInstance)13 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)5 UAVServer (com.creditease.monitor.UAVServer)3 Map (java.util.Map)3 FastClasspathScanner (io.github.lukehutch.fastclasspathscanner.FastClasspathScanner)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ServerVendor (com.creditease.monitor.UAVServer.ServerVendor)1 DubboServiceProfileInfo (com.creditease.uav.profiling.handlers.dubbo.DubboServiceProfileInfo)1 LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)1 ProfileElement (com.creditease.uav.profiling.spi.ProfileElement)1 LimitLinkedHashMap (com.creditease.uav.util.LimitLinkedHashMap)1 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 LinkedList (java.util.LinkedList)1