Attach the Java Agent to a Running JVM Process

Attaching the agent to a running JVM allows you to install the Java Agent without requiring a JVM restart. This approach would normally be used alongside adding the ‑javaagent argument to the JVM startup script, or some other persistent approach to ensure that the agent is loaded again at the next JVM restart. However, the dynamic attachment allows you to install the agent when restarting the JVM is not possible or convenient.

Note: In some scenarios, you need to use double backslashes instead of single backslashes. For example:
-javaagent:C:\\appdynamics\\javaagent.jar

Dynamic agent attachment works if:

  • JVM is => 1.6.
  • JVM is an Oracle (HotSpot) JVMs (unavailable for IBM or JRockit JVMs).

Other considerations include:

  • Do not attach the agent dynamically to an environment that is already instrumented (either by the Splunk AppDynamics Java Agent or another type of agent). Doing so can cause unforeseeable issues and errors.
  • Attaching the Splunk AppDynamics Java Agent to a running environment will impact the performance of the application while the agent performs the class retransformation needed to instrument the application. The agent overhead will return to its normal operating level when it finishes the process, but it is important to consider the potential performance impact to production services.

Attach the Agent to the JVM

To attach the agent to the JVM:
  1. Determine the PID of the JVM to which you want to attach.
    • For Linux, use:
      ps -A | grep java
    • On Windows, use:
      jps -l
  2. Run the following command, replacing the placeholders for the path to the tools.jar file in your JDK, path to the Splunk AppDynamics Java Agent home directory, and the JVM process ID with values appropriate for your environment:
    java -Xbootclasspath/a:<path_to_jdk>/lib/tools.jar -jar /<agent_home>/javaagent.jar <jvm_process_id> appdynamics.controller.hostName=<controller_hostname>,appdynamics.controller.port=<controller_port_no>,appdynamics.controller.ssl.enabled=false,appdynamics.agent.applicationName=<app_name>,appdynamics.agent.tierName=<agent_tier_name>,appdynamics.agent.nodeName=<agent_node_name
    Use the equivalent paths for Windows, including drive letter. The following shows an example with system output included:
    [appduser@my_centos6 ~]$ ps -A | grep java 6780 pts/1 00:00:04 java [appduser@my_centos6 ~]$ java -Xbootclasspath/a:/usr/java/jdk1.7.0_79/lib/tools.jar -jar /home/appduser/appagent/javaagent.jar 6780 Attaching to VM [6780] agent path >>>/home/appduser/appagent/javaagent.jar=