啥是 Java Agent

First java agent project

ByteBuddy in Agent:

https://www.infoq.cn/article/Easily-Create-Java-Agents-with-ByteBuddy/

premain 适合 Agent 增强字节码做监控 (monitor), 埋点:

  1. https://github.com/stagemonitor/stagemonitor
  2. https://github.com/apache/skywalking

agentmain 适合 attach JVM 做热部署和 debug JVM:

https://github.com/alibaba/arthas

由于 Agent 会在 classpath 下,因此在 Agent JAR 包中加入 Spring AutoConfiguration 类,利用依赖大于配置的能力给应用加入监控,日志等一些列功能。

Dynamic agents

VirtualMachine vm = VirtualMachine.attach(vmPid);
vm.loadAgent(agentFilePath);
vm.detach();