Springboot runtime loads statsd-jvm-profiler

  jvm, springboot

Order

Statsd-jvm-Profiler is a JVM agent Profiler developed by etsy, which sends profile data to statsd.

-javagen load

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

Runtime dynamic loading

Copy the jar package to the main resource directory of the spring boot project, and then

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

Built-in httpServer

The agent has a built-in http server with a default port of 5005 and can access the following path
http://localhost:5005/errors
http://localhost:5005/isRunning
http://localhost:5005/profilers
http://localhost:5005/disable …
http://localhost:5005/status/ …

graphite

In graphite, the gauges of the statsd-jvm-profiler prefix is enough.

doc