I wrote JVM monitoring with JMX. I connect MBean sever connection with ths following url
service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi
It worked using localhost but I would to connect other machine JVM and I also used this;
service:jmx:rmi:///jndi/rmi://OTHER_SERVER_PORT:9999/jmxrmi
It doesn't work.I goggling about this and some example tell to add the following JVM options to target machine JVM.
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
So where to add the above JVM options? And how to connect other machine JVM using JMX service url? This is my sample class
public class JMXRemote {
public static void main(String[] args) throws Exception {
JMXServiceURL url = new JMXServiceURL(
"service:jmx:rmi:///jndi/rmi://OTHER_PC_PORT:9999/jmxrmi");
JMXConnector c = JMXConnectorFactory.connect(url);
MBeanServerConnection mbsc = c.getMBeanServerConnection();
Object o = mbsc.getAttribute(new ObjectName("java.lang:type=Memory"),
"HeapMemoryUsage");
CompositeData cd = (CompositeData) o;
System.out.println(cd.get("committed"));
}
}