springboot运行时加载statsd-jvm-profiler

statsd-jvm-profiler是etsy开发的一个 JVM 代理 Profiler,其将Profile数据发送到 StatsD.

-javaagent加载

-javaagent:/usr/etsy/statsd-jvm-profiler/statsd-jvm-profiler.jar=server=statsdHost,port=statsdPort

运行时动态加载

将该jar包拷贝到spring boot工程的main resource目录下,然后

@Bean
    public CommandLineRunner loadProfilerAgent(){
        return new CommandLineRunner() {
            @Override
            public void run(String... strings) throws Exception {
                ApplicationPid pid = new ApplicationPid();
                try{
                    com.sun.tools.attach.VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(pid.toString());
                    ClassLoader classLoader = getClass().getClassLoader();
                    String profilerJarPath = classLoader.getResource("statsd-jvm-profiler-2.0.0.jar").getPath();
                    String agentArgs = "server="+statsdHost+",port="+statsdPort;
                    vm.loadAgent(profilerJarPath, agentArgs);
                    vm.detach();
                    System.out.println("Dynamically loaded StatsD JVM Profiler Agent...");
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        };
    }

内置httpServer

该agent内置了一个http server,默认端口为5005,可以访问如下几个path
http://localhost:5005/errors
http://localhost:5005/isRunning
http://localhost:5005/profilers
http://localhost:5005/disable/:profiler
http://localhost:5005/status/profiler/:profiler

graphite

在graphite里头,statsd-jvm-profiler前缀的gauges就是了。

doc

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容