Search in sources :

Example 1 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class DubboHookProxy method InsertInterceptToClients.

private void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {
    if (isHookEventDone("InsertInterceptToClients")) {
        return;
    }
    InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
    String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
    String basePath = (String) ic.get(InterceptConstants.BASEPATH);
    final String appid = MonitorServerUtil.getApplicationId(contextPath, basePath);
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * inject ServiceBean for profiling
     */
    dpInstall.installProxy("com.alibaba.dubbo.config.spring.ServiceBean", new String[] { "com.creditease.uav.hook.dubbo.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("onApplicationEvent".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DubboIT.class);
                m.insertAfter("{mObj=new DubboIT(\"" + appid + "\");mObj.doProfiling(new Object[]{this,$1});}");
            }
        }
    }, false);
    /**
     * inject Dubbo's MonitorFilter to get Service & Consumer Perf Data
     */
    dpInstall.installProxy("com.alibaba.dubbo.monitor.support.MonitorFilter", new String[] { "com.creditease.uav.hook.dubbo.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("invoke".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DubboIT.class);
                m.insertBefore("{DubboIT.doMonitorStart(\"" + appid + "\",new Object[]{$1,$2},false,null);}");
                m.insertAfter("{DubboIT.doMonitorEnd(new Object[]{$1,$2,$_},true,null);}");
                dpInstall.addCatch(m, "{DubboIT.doMonitorEnd(new Object[]{$1,$2},true,$e);throw $e;}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) DubboIT(com.creditease.uav.hook.dubbo.interceptors.DubboIT) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Example 2 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class RocketmqHookProxy method doInstallDProxy.

public void doInstallDProxy(ClassLoader webapploader, final String appid) {
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * install proxy to rocketmqClient
     */
    DynamicProxyProcessor processor = new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ((m.getExceptionTypes().length != 0 || "shutdown".equals(m.getName()) || "unsubscribe".equals(m.getName()) || "registerMessageListener".equals(m.getName())) && /*
                            * this method could be blocked for a long time, the statics is meaningless, so we ignore it.
                            */
            !("pullBlockIfNotFound").equals(m.getName())) {
                if ("registerMessageListener".equals(m.getName())) {
                    if ("MessageListenerConcurrently".equals(m.getParameterTypes()[0].getSimpleName())) {
                        m.insertBefore("{$1=(MessageListenerConcurrently)RocketmqIT.start(\"" + appid + "\",this,\"" + m.getName() + "\",$args);}");
                    } else if ("MessageListenerOrderly".equals(m.getParameterTypes()[0].getSimpleName())) {
                        m.insertBefore("{$1=(MessageListenerOrderly)RocketmqIT.start(\"" + appid + "\",this,\"" + m.getName() + "\",$args);}");
                    }
                    m.insertAfter("{RocketmqIT.end(-1,\"" + m.getName() + "\");}");
                } else if (m.getName().equals("pull") && !m.getReturnType().getSimpleName().equals("PullResult")) {
                    m.insertBefore("{$5=(PullCallback)RocketmqIT.start(\"" + appid + "\",this,\"" + m.getName() + "\",$args);}");
                    m.insertAfter("{RocketmqIT.end(-1,\"" + m.getName() + "\");}");
                } else {
                    m.insertBefore("{RocketmqIT.start(\"" + appid + "\",this,\"" + m.getName() + "\",$args);}");
                    m.insertAfter("{RocketmqIT.end(1,\"" + m.getName() + "\");}");
                }
                dpInstall.addCatch(m, "RocketmqIT.end(0,\"" + m.getName() + "\");");
            }
        }
    };
    dpInstall.installProxy("com.alibaba.rocketmq.client.producer.DefaultMQProducer", new String[] { "com.creditease.uav.hook.rocketmq.interceptors", "com.alibaba.rocketmq.client.consumer.listener" }, processor, false);
    dpInstall.installProxy("com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer", new String[] { "com.creditease.uav.hook.rocketmq.interceptors" }, processor, false);
    dpInstall.installProxy("com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer", new String[] { "com.creditease.uav.hook.rocketmq.interceptors", "com.alibaba.rocketmq.client.consumer" }, processor, false);
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Example 3 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class AredisHookProxy method doProxyInstall.

public void doProxyInstall(ClassLoader webapploader, final String appid) {
    /**
     * set the webapploader is the target classloader
     */
    dpInstaller.setTargetClassLoader(webapploader);
    dpInstaller.defineField("mMap", Map.class, "org.aredis.cache.RedisCommandObject", "new java.util.HashMap()");
    dpInstaller.installProxy("org.aredis.cache.RedisCommandObject", new String[] { "com.creditease.uav.hook.redis.aredis.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("sendRequest".equals(m.getName())) {
                dpInstaller.defineLocalVal(m, "mObj", AredisCommandObjectIT.class);
                m.insertBefore("{mObj = new AredisCommandObjectIT(\"" + appid + "\");" + "mObj.doAsyncStart(new Object[]{$1, $2, $3, commandInfo});" + "mMap.put(\"mObj\",mObj);}");
            }
            if ("receiveResponse".equals(m.getName())) {
                m.insertAfter("{AredisCommandObjectIT mObj = (AredisCommandObjectIT)mMap.get(\"mObj\");" + "mObj.doAsyncEnd(new Object[]{commandInfo});}");
            }
        }
    }, false);
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor) AredisCommandObjectIT(com.creditease.uav.hook.redis.aredis.interceptors.AredisCommandObjectIT)

Example 4 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class LettuceHookProxy method doProxyInstall.

public void doProxyInstall(ClassLoader webapploader, final String appid) {
    /**
     * set the webapploader is the target classloader
     */
    dpInstaller.setTargetClassLoader(webapploader);
    dpInstaller.installProxy("com.lambdaworks.redis.protocol.CommandHandler", new String[] { "com.creditease.uav.hook.redis.lettuce.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("write".equals(m.getName())) {
                DPClass[] ccs = m.getParameterTypes();
                if (ccs.length == 1) {
                    m.insertBefore("{LettuceCommandHandlerIT.start(\"" + appid + "\", new Object[]{$1.getType(), ((java.net.InetSocketAddress)remote()).getHostName(), new Integer(((java.net.InetSocketAddress)remote()).getPort())});}");
                    m.insertAfter("{LettuceCommandHandlerIT.end(new Object[]{$_});}");
                    dpInstaller.addCatch(m, "LettuceCommandHandlerIT.end(new Object[]{$e});");
                } else {
                // TODO
                // logger.debug("write with more args", null);
                }
            }
        }
    }, false);
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Example 5 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class MongoClientHookProxy method doInstallDProxy.

public void doInstallDProxy(ClassLoader webapploader, final String appid) {
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * install proxy to MongoClient
     */
    dpInstall.installProxy("com.mongodb.MongoClient", new String[] { "com.creditease.uav.hook.mongoclients.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("getDatabase".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", MongoClientIT.class);
                m.insertAfter("{mObj=new MongoClientIT(\"" + appid + "\");$_=mObj.doInstall($_);}");
            }
        }
    }, false);
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) MongoClientIT(com.creditease.uav.hook.mongoclients.interceptors.MongoClientIT) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Aggregations

DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)21 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)20 JdbcDriverIT (com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)4 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)3 ServerVendor (com.creditease.monitor.UAVServer.ServerVendor)2 DubboIT (com.creditease.uav.hook.dubbo.interceptors.DubboIT)1 ApacheAsyncHttpClientIT (com.creditease.uav.hook.httpclients.async.interceptors.ApacheAsyncHttpClientIT)1 JaxWSHookIT (com.creditease.uav.hook.jaxws.interceptors.JaxWSHookIT)1 DBCPIT (com.creditease.uav.hook.jdbc.pools.dbcp.interceptors.DBCPIT)1 MybatisIT (com.creditease.uav.hook.jdbc.pools.mybatis.interceptors.MybatisIT)1 MongoClientIT (com.creditease.uav.hook.mongoclients.interceptors.MongoClientIT)1 RabbitmqIT (com.creditease.uav.hook.rabbitmq.interceptors.RabbitmqIT)1 AredisCommandObjectIT (com.creditease.uav.hook.redis.aredis.interceptors.AredisCommandObjectIT)1 DPClass (com.creditease.uav.monitorframework.dproxy.bytecode.DPClass)1 WebServiceListenerIT (com.creditease.uav.monitorframework.webservice.interceptors.WebServiceListenerIT)1 FastClasspathScanner (io.github.lukehutch.fastclasspathscanner.FastClasspathScanner)1