java agent 简单例子  
   
所属分类 javaagent
浏览量 2186
Java agent 探针
在 应用 main 之前执行, 可以做一些 字节码修改 类替换
很多应用监控组件就是这么干的
public static void premain(String agentArgs, Instrumentation inst)
META-INF/MANIFEST.MF 文件增加
Premain-Class: dyyx.agent.HelloAgent
需要在pom里增加
        
            
                org.apache.maven.plugins
                maven-jar-plugin
                2.3.1
                
                    
                        
                            dyyx.agent.HelloAgent
                        
                    
                
            
        
    
    
启动应用增加参数
-javaagent:/Users/dugang/fun/hellocode/project/helloagent/target/helloagent-1.0.0.jar=agentargs
java -javaagent:/Users/dugang/fun/hellocode/project/helloagent/target/helloagent-1.0.0.jar=agentargs  Hello
tomcat 测试
catalina.sh 里增加 jvm参数
-javaagent:/Users/dugang/soft/tomcat/agent9010/agent/helloagent-1.0.0.jar=agentargsForTomcat
JAVA_OPTS="$JAVA_OPTS -javaagent:/Users/dugang/soft/tomcat/agent9010/agent/helloagent-1.0.0.jar=agentargsForTomcat"
helloagent-1.0.0.jar 被所有应用共享
两个应用 共享  dyyx.agent.HelloAgent.map 
完整例子代码
https://gitee.com/dyyx/hellocode/tree/master/project/helloagent
应用读写 dyyx.agent.HelloAgent.map 的两个jsp代码
https://gitee.com/dyyx/hellocode/tree/master/project/helloagent/doc/webapp
 jvm外挂工具揭秘 
 上一篇  
   
 下一篇  
 nginx状态监控 
 使用prometheus和grafana监控JVM 
 应用监控资料收集整理 
 时间序列数据库介绍 
 系统及应用监控工具 
 linux系统常用监控指标