To programetically access the remote JVM statistics (JVM system parameters, Thread statististics, Memomy information, GC Information and other information), JMX can be used. For that, remote JVM must allow JMX connection (Check this on how to activate JMX in remote JVM). Basically you need following -D parameters to be set in the remote JVM with appropriate values:
-Dcom.sun.management.jmxremote.port=1234
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=127.0.0.1
Once the above setting is done, connect to the JMX port and get different Mbean information from the remote server from your application: Following is some sample code:
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + HOST + ":" + PORT + "/jmxrmi");
JMXConnector jmxConnector = JMXConnectorFactory.connect(url);
MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();
With this mbeanServerConnection
, you can access different managed beans and get the required information from the MX beans. For system properties, you need to get the RuntimeMXBean
bean and invoke getSystemProperties()
to get all system parameters.