It is necessary at some point of a project, to analyse consumption of resources by an application.
In Java, we have JMX, which allows to access the internal data of a running JVM (JMX stands for Java Management eXtension). I got so many issues using the recommended configuration, given by wildfly and redhat, to analyse the memory consumption of a Wildfly instance, that I decided to document the steps.
If you look at the wildfly documentation, it well written that you can enable the JMX management by changing the standalone.xml configuration file. It did not work for me (connection refused for all the tested variations).
The standalone.conf is the configuration file responsible of all the parameters passed to the standalone.sh file, itself responsible of the JBOSS startup. Here is the one and only one configuration that did work for me to enable JMX remote access:
#(1) share classloader if [ "x$JBOSS_MODULES_SYSTEM_PKGS" = "x" ]; then JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,org.jboss.logmanager" fi #.... # Sample JPDA settings for remote socket debugging #... # (2) setup the jmx configuration # (2.a) begin with logger concerns JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.jboss.logmanager.LogManager" JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:$JBOSS_HOME/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-2.0.4.Final.jar" JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:$JBOSS_HOME/modules/system/layers/base/org/jboss/log4j/logmanager/main/log4j-jboss-logmanager-1.1.2.Final.jar" JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:$JBOSS_HOME/modules/system/layers/base/org/jboss/logging/main/jboss-logging-3.3.0.Final.jar" # (2.b) JMX setup JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=<PORT>" JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false" JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false" JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.local.only=false" JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote" JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=<IP>" JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=<PORT>"
Note that the order is really important, it allows the JVM to load the logger early, which is a requirement to correcly setup the JMX configuration and JBOSS at the same time.
Simply start JBOSS, you should not see any error regarding the logger
What is good with this technique is that you don't need to configure whatever jboss-client.jar file in the classpath of Jconsole. Simply launch JConsole and type your IP:PORT as follows:
You should be able to follow the evolution of your memory consumption