Sunday 1 May 2016

Monitoring java process running under jetty using JConsole

I came across a situation recently where an application running under jetty were having some performance issues which eventually resulted in high latency. After spending quite sometime troubleshooting the problem with no conclusion we had to profile the application to see how many threads are running, how much heap is getting used etc.

To profile the application we had chosen JConsole. Now at first it seemed to be a straightforward setup (After all its just a connection to a given host and port) however it took us a while. Hence sharing the steps here which should be followed to have a hassle free setup.

Step 1:

Add following parameters inside start.ini file found in jetty distribution directory/folder:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=1099 # 1099 is default JMX Port.
-Djava.rmi.server.hostname=Your_Machine_IP


Step 2:

Make below changes inside (Adding a connector for remote JMX connection) etc/jetty-jmx.xml as per https://wiki.eclipse.org/Jetty/Tutorial/JMX:

<new class="org.eclipse.jetty.jmx.ConnectorServer" id="ConnectorServer">
<arg>
<new class="javax.management.remote.JMXServiceURL">
<arg type="java.lang.String">rmi</arg>
<arg type="java.lang.String">
<arg type="java.lang.Integer"><systemproperty default="1099" name="jetty.jmxrmiport"></systemproperty></arg>
<arg type="java.lang.String">/jndi/rmi://<systemproperty default="localhost" name="jetty.jmxrmihost">:<systemproperty default="1099" name="jetty.jmxrmiport">/jmxrmi</systemproperty></systemproperty></arg>
</arg></new>
</arg>
<arg>org.eclipse.jetty.jmx:name=rmiconnectorserver</arg>
<call name="start">
</call></new>


Note: Above xml configuration is already present inside etc/jetty-jmx.xml file but its commented by default. So just uncomment the xml tag.

Now we are all done. Open the JConsole application and connect to the application using below URL:

service:jmx:rmi:///jndi/rmi://Your_Machine_IP:1099/jmxrmi

Now we should be able to see the real-time application activity in terms of JConsole graphs.

No comments:

Post a Comment