Search in sources :

Example 6 with ServerVendor

use of com.creditease.monitor.UAVServer.ServerVendor in project uavstack by uavorg.

the class HttpDataObserverWorker method stop.

@Override
public void stop() {
    GlobalFilterDispatchListener listener = (GlobalFilterDispatchListener) InterceptSupport.instance().getEventListener(GlobalFilterDispatchListener.class);
    // unregister Observer to GlobalFilterDispatchListener
    ServerVendor sv = (ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
    /**
     * MSCP
     */
    if (sv == ServerVendor.MSCP) {
    } else /**
     * JEE
     */
    {
        listener.unregisterHandler("HttpJEEJVMObserver()");
        listener.unregisterHandler("HttpJEEMonitorObserver");
        listener.unregisterHandler("HttpJEEProfileObserver");
    }
    monitorMap.clear();
    monitorMBeanMap.clear();
    profileMap.clear();
    profileMBeanMap.clear();
}
Also used : GlobalFilterDispatchListener(com.creditease.uav.appserver.listeners.GlobalFilterDispatchListener) ServerVendor(com.creditease.monitor.UAVServer.ServerVendor)

Example 7 with ServerVendor

use of com.creditease.monitor.UAVServer.ServerVendor in project uavstack by uavorg.

the class JdbcHookProxy method injectDataSource.

/**
 * inject ApplicationServer DataSource
 *
 * @param webapploader
 * @param appid
 */
private void injectDataSource(InterceptContext ic) {
    Object resObj = ic.get(InterceptConstants.RESOURCEOBJ);
    Object resCfgObj = ic.get(InterceptConstants.RESOURCECFG);
    if (resObj == null || resCfgObj == null) {
        return;
    }
    if (isHookEventDone("isInjectDataSource")) {
        return;
    }
    JdbcDriverIT jdbcDriverIT = new JdbcDriverIT(this.getAppID(ic));
    ServerVendor vendor = (ServerVendor) this.getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
    /**
     * NOTE: Tomcat use ResourceFactory to get DataSource Object, then we can get the url from config (Reference)
     * Diff AppServer the behavior may be not the same. SpringBoot default uses Tomcat as its default app server
     */
    if (vendor == ServerVendor.TOMCAT || vendor == ServerVendor.SPRINGBOOT) {
        Object dsProxy = jdbcDriverIT.doProxyDataSource(resObj, resCfgObj, "Tomcat");
        ic.put(InterceptConstants.RESOURCEOBJ, dsProxy);
    }
}
Also used : ServerVendor(com.creditease.monitor.UAVServer.ServerVendor) JdbcDriverIT(com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)

Example 8 with ServerVendor

use of com.creditease.monitor.UAVServer.ServerVendor in project uavstack by uavorg.

the class Log4jHookProxy method InsertIntercept.

private void InsertIntercept(HookContext context, ClassLoader webapploader) {
    if (isHookEventDone("insertLog4jIntercepter")) {
        return;
    }
    ServerVendor vendor = (ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
    if (vendor == ServerVendor.SPRINGBOOT) {
        return;
    }
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    // 定义一个类里面的hook变量并初始化,防止每次拦截write时都初始化对象
    dpInstall.defineField("uavLogHook", LogIT.class, "org.apache.log4j.helpers.QuietWriter", "new LogIT()");
    // 定义换行符变量(与log4j中保持一致)
    dpInstall.defineField("uavLogHookLineSep", String.class, "org.apache.log4j.helpers.QuietWriter", "System.getProperty(\"line.separator\")");
    dpInstall.installProxy("org.apache.log4j.helpers.QuietWriter", new String[] { "com.creditease.uav.log.hook.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("write".equals(m.getName())) {
                m.insertBefore("{if(!$1.equals(uavLogHookLineSep)){$1=uavLogHook.formatLog($1);}}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) ServerVendor(com.creditease.monitor.UAVServer.ServerVendor) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Example 9 with ServerVendor

use of com.creditease.monitor.UAVServer.ServerVendor 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 10 with ServerVendor

use of com.creditease.monitor.UAVServer.ServerVendor in project uavstack by uavorg.

the class ComponentProfileHandler method doProfiling.

@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;
    }
    /**
     * 1.5 for other none JEE or Spring tech profiling
     */
    dubboProfileHandler.doProfiling(elem, context);
    /**
     * 2.load available annotation classes
     */
    Map<String, Class<?>> annoAvailableClasses = new HashMap<String, Class<?>>();
    for (String annoClsName : componentClassNames) {
        try {
            Class<?> c = webappclsLoader.loadClass(annoClsName);
            annoAvailableClasses.put(annoClsName, c);
        } catch (ClassNotFoundException e) {
            // ignore
            if (this.logger.isDebugable()) {
                this.logger.warn("Annotation Class [" + annoClsName + "] is not found in web application [" + elem.getRepository().getProfile().getId() + "]", e);
            }
        }
    }
    /**
     * 2.1 load available interface classes
     */
    Map<String, Class<?>> interfaceAvailableClasses = new HashMap<String, Class<?>>();
    for (String interfaceClsName : componentInterfaceNames) {
        try {
            Class<?> c = webappclsLoader.loadClass(interfaceClsName);
            interfaceAvailableClasses.put(interfaceClsName, c);
        } catch (ClassNotFoundException e) {
            // ignore
            if (this.logger.isDebugable()) {
                this.logger.warn("Interface Class [" + interfaceClsName + "] is not found in web application [" + elem.getRepository().getProfile().getId() + "]", e);
            }
        }
    }
    /**
     * 3. see what kind of components we could get via annotations
     */
    UAVServer.ServerVendor vendor = (ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
    /**
     * NOTE: currently for spring boot, we use its base classloader as the webappclassloader, and should scan all
     * packages
     */
    ClassLoader[] classLoaders = null;
    if (vendor != UAVServer.ServerVendor.SPRINGBOOT) {
        classLoaders = new ClassLoader[] { webappclsLoader };
        String scanPackages = System.getProperty("com.creditease.uav.uavmof.profile.package.header");
        if (StringHelper.isEmpty(scanPackages)) {
            scanPackage[0] = "com";
        } else {
            scanPackage = scanPackages.split(",");
        }
    } else {
        scanPackage[0] = "";
    }
    FastClasspathScanner fcs = new FastClasspathScanner(classLoaders, scanPackage);
    fcs.scan();
    // store FastClasspathScanner instance into ProfileContext
    context.put(FastClasspathScanner.class, fcs);
    /**
     * 4.tide components we get from annotations & deployment descriptors
     */
    // store the DescriptorProcessor instance for better performance
    Map<String, DescriptorProcessor> dpInstances = new LinkedHashMap<String, DescriptorProcessor>();
    // get web application root
    InterceptContext itContext = context.get(InterceptContext.class);
    String webAppRoot = (String) itContext.get(InterceptConstants.BASEPATH);
    for (String componentClassName : componentClassNames) {
        // set the instance id = simple name of the annotation class
        ProfileElementInstance inst = elem.getInstance(componentClassName);
        // load componentsByAnno first
        loadComponentsByAnno(context, webappclsLoader, fcs, annoAvailableClasses, componentClassName, inst);
    }
    for (String componentClassName : componentInterfaceNames) {
        // set the instance id = simple name of the annotation class
        ProfileElementInstance inst = elem.getInstance(componentClassName);
        // load componentsByInterface
        loadComponentsByInterface(context, webappclsLoader, fcs, interfaceAvailableClasses, componentClassName, inst);
    }
    String[] allComponentNames = new String[componentClassNames.length + componentInterfaceNames.length];
    System.arraycopy(componentClassNames, 0, allComponentNames, 0, componentClassNames.length);
    System.arraycopy(componentInterfaceNames, 0, allComponentNames, componentClassNames.length, componentInterfaceNames.length);
    for (String componentClassName : allComponentNames) {
        ProfileElementInstance inst = elem.getInstance(componentClassName);
        // try to load componentsByDescriptor
        loadComponentsByDescriptor(dpInstances, webAppRoot, context, componentClassName, inst);
        // try to load componentsByDynamic Creation, currently is for servlet 3.x and webservice
        loadComponentsByDynamic(itContext, componentClassName, inst, context, annoAvailableClasses, fcs);
        /**
         * NOTE: in order to control the monitor data url, we need collect ther servlet url to help to identify if
         * an url is a service url
         */
        if (componentClassName.equalsIgnoreCase("javax.servlet.annotation.WebServlet")) {
            collectServletInfoForMonitor(inst);
        }
        /**
         * collectProfileServiceMap
         */
        collectProfileServiceMap(componentClassName, inst);
    }
    /**
     * 4.1 add common info instance from descriptor to profile element
     */
    // web.xml related common info
    loadCommonInfoFromWebXML(elem, dpInstances, webAppRoot, context);
    /**
     * 5.confirm there is update
     */
    elem.getRepository().setUpdate(true);
    // release resources quickly
    dpInstances.clear();
}
Also used : ProfileElementInstance(com.creditease.uav.profiling.spi.ProfileElementInstance) FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UAVServer(com.creditease.monitor.UAVServer) LinkedHashMap(java.util.LinkedHashMap) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) ServerVendor(com.creditease.monitor.UAVServer.ServerVendor) ServerVendor(com.creditease.monitor.UAVServer.ServerVendor)

Aggregations

ServerVendor (com.creditease.monitor.UAVServer.ServerVendor)13 GlobalFilterDispatchListener (com.creditease.uav.appserver.listeners.GlobalFilterDispatchListener)5 UAVServer (com.creditease.monitor.UAVServer)2 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)2 DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)2 HashMap (java.util.HashMap)2 AbsGlobalFilterHandler (com.creditease.monitor.globalfilter.AbsGlobalFilterHandler)1 UAVServerJEEController (com.creditease.monitor.globalfilter.jee.UAVServerJEEController)1 InterceptSupport (com.creditease.monitor.interceptframework.InterceptSupport)1 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)1 InterceptEventListener (com.creditease.monitor.interceptframework.spi.InterceptEventListener)1 ClientSpanInvokeChainHandler (com.creditease.uav.apm.invokechain.handlers.ClientSpanInvokeChainHandler)1 MethodSpanInvokeChainHandler (com.creditease.uav.apm.invokechain.handlers.MethodSpanInvokeChainHandler)1 ServiceSpanInvokeChainHandler (com.creditease.uav.apm.invokechain.handlers.ServiceSpanInvokeChainHandler)1 JEEServiceRunGlobalFilterHandler (com.creditease.uav.apm.invokechain.jee.JEEServiceRunGlobalFilterHandler)1 JdbcDriverIT (com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)1 Profile (com.creditease.uav.profiling.spi.Profile)1 ProfileElementInstance (com.creditease.uav.profiling.spi.ProfileElementInstance)1 FastClasspathScanner (io.github.lukehutch.fastclasspathscanner.FastClasspathScanner)1 IOException (java.io.IOException)1