Class GetAgentProperties

java.lang.Object
co.elastic.apm.attach.GetAgentProperties

public class GetAgentProperties extends Object
  • Constructor Details

    • GetAgentProperties

      public GetAgentProperties()
  • Method Details

    • main

      public static void main(String[] args) throws Exception
      Prints the system and agent properties of the JVM with the provided pid to stdout, it a way that can be consumed by Properties.load(InputStream). This works by attaching to the JVM with the provided pid and by calling VirtualMachine.getSystemProperties() and VirtualMachine.getAgentProperties().

      In getAgentAndSystemPropertiesSwitchUser(java.lang.String, co.elastic.apm.attach.UserRegistry.User), a new JVM is forked running this main method. This JVM runs in the context of the same user that runs the JVM with the provided pid. This indirection is needed as it's not possible to attach to a JVM that runs under a different user.

      Parameters:
      args - contains a single argument - the process id of the target VM
      Throws:
      Exception
    • getAgentAndSystemProperties

      public static Properties getAgentAndSystemProperties(String pid, UserRegistry.User user) throws Exception
      Attaches to the VM with the given pid and gets the agent and system properties.
      Parameters:
      pid - The pid of the target VM, If it is current VM, this method will fork a VM for self-attachment.
      user - The user that runs the target VM. If this is not the current user, this method will fork a VM that runs under this user.
      Returns:
      The agent and system properties of the target VM.
      Throws:
      Exception - In case an error occurs while attaching to the target VM.