JVM Agent

Another variant is Jolokia’s JVM agent which does not need any special container environment. The only dependency is on Oracle’s JDK 11 or later as runtime, since it contains a lightweight HTTP Server used for exposing the Jolokia protocol. This agent is the most generic one which can instrument any Java application using a JDK11+. It is suitable for situations where the other agents don’t fit. Also, it can be used for dynamically attaching an agent to a running Java process (this option however is going to be removed after JDK 21).

For using this agent, the following argument to the Java application to instrument has to be given:

$ java ... -javaagent:/path/to/jolokia-agent-jvm-2.0.3-javaagent.jar

By default, the agent will listen on port 8778, but this can be configured as well as other aspects like authentication:

  • Provide options on the commandline as key-value pairs:

    $ java ... -javaagent:jolokia-agent-jvm-2.0.3-javaagent.jar=port=7777,host=localhost
  • Via a properties file

    $ java ... -javaagent:jolokia-agent-jvm-2.0.3-javaagent.jar=config=/path/to/config.properties
  • Via packaging a jolokia-agent.properties top level in the agent.jar

Options are used in the given precedence, the former overwriting the later values.

For attaching the agent dynamically to a running Java process, the following command can be used to get a quick help

$ java -jar /path/to/jolokia-agent-jvm-2.0.3-javaagent.jar --help
Dynamic loading of agents will be removed at some point. See JEP 451 for details.

For more details and usage examples please refer to the reference manual.