栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

skywalking

skywalking

修改应用的服务名称

1.系统配置

2.探针配置

3.在skywalking安装目录agent目录下配置文件中,指定服务名称

排除不需要监听的请求

1.拷贝ignore-plugin插件到 plugins目录下
2.在启动命令上加上配置

告警

在alarm-settings配置文件中配置告警的规则,然后配置webhooks的地址,就跟发送短信或者企业微信了

java agent原理


创建一个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.PreMainAgent
                            true
                            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开头的类

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/730969.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号