Remote JVM monitoring using VisualVM
Most of the modern JVM application frameworks like Spring Boot, Dropwizard and Ktor uses executable jars to bootstrap application with servers embedded inside the jar. The following steps will allow you to monitor the remote JVM running in cloud (or in house data center) using SSH port forwarding and Java JMX.
In order to monitor the remote JVM, the java process needs to be started with extra system properties to enable JMX features and you should be able to SSH into the machine where the JVM is running.
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10006 -Dcom.sun.management.jmxremote.rmi.port=10006 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost -jar spring-boot-application.jar
ssh -L 10006:localhost:10006 remote-user@server-host-or-ip
Open VisualVM
File Menu -> Add JMX Connection
Give a suitable name in 'Display name'
Uncheck 'Use security credentials'
Uncheck 'Do not require SSL connection'
'Connection' as service:jmx:rmi:///jndi/rmi://localhost:10006/jmxrmi
In order to monitor the remote JVM, the java process needs to be started with extra system properties to enable JMX features and you should be able to SSH into the machine where the JVM is running.
Start the Java application (or Java Process) with JMX enabled as given below:
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10006 -Dcom.sun.management.jmxremote.rmi.port=10006 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost -jar spring-boot-application.jar
Create a SSH tunnel with port forwarding for JMX port
ssh -L 10006:localhost:10006 remote-user@server-host-or-ip
Connect with VisualVM
Open VisualVM
File Menu -> Add JMX Connection
Give a suitable name in 'Display name'
Uncheck 'Use security credentials'
Uncheck 'Do not require SSL connection'
'Connection' as service:jmx:rmi:///jndi/rmi://localhost:10006/jmxrmi
Comments
Post a Comment