1.系统配置
2.探针配置
3.在skywalking安装目录agent目录下配置文件中,指定服务名称
1.拷贝ignore-plugin插件到 plugins目录下
2.在启动命令上加上配置
在alarm-settings配置文件中配置告警的规则,然后配置webhooks的地址,就跟发送短信或者企业微信了
创建一个maven项目
import java.lang.instrument.Instrumentation;
public class PreMainAgent {
public static void premain(String arguments , Instrumentation instrumentation){
System.out.println("=====premain 执行,参数为:"+arguments);
}
}
pom.xml
org.apache.maven.plugins >maven-assembly-plugin>false > jar-with-dependencies true com.demo.PreMainAgent com.demo.PreMainAgenttrue true make-assembly package single
然后maven clean package。
解压jar后可以看见生成MANIFEST.MF文件,里面的信息就是maven-assembly-plugin 中配置的
在其他项目中配置启动命令
bytebuddy拦截增加依赖包
net.bytebuddy byte-buddy 1.9.12 net.bytebuddy byte-buddy-agent 1.9.12
修改PreMainAgent
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import net.bytebuddy.utility.JavaModule;
import java.lang.instrument.Instrumentation;
public class PreMainAgent {
public static void premain(String arguments , Instrumentation instrumentation){
System.out.println("=====premain 执行,参数为:"+arguments);
AgentBuilder.Transformer transformer = new AgentBuilder.Transformer() {
public DynamicType.Builder> transform(DynamicType.Builder> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule javaModule) {
return builder.method(ElementMatchers.any()).intercept(MethodDelegation.to(MyInterceptor.class));
}
};
//指定拦截以com.example.demo开头的包名
ElementMatcher.Junction type = ElementMatchers.nameStartsWith("com.example.demo");
new AgentBuilder.Default()
.type(type)
.transform(transformer).installOn(instrumentation);
}
}
增加拦截器类
import net.bytebuddy.implementation.bind.annotation.*;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;
public class MyInterceptor {
@RuntimeType
public static Object intercept(@Origin Method method, @SuperCall Callable> callable, @AllArguments Object[] objects) throws Exception {
long start = System.currentTimeMillis();
Object object = callable.call();
System.out.println("执行时间为:" + (System.currentTimeMillis() - start));
return object;
}
}
执行效果:
拦截了以com.example.demo开头的类



