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();
}
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();
}
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);
}
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);
}
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();
}
Aggregations