0

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"));
      }
  }
Sai Ye Yan Naing Aye
  • 6,622
  • 12
  • 47
  • 65
  • You have to add the below options in your VM arguments. If you are using eclipse go to Run -> Run Configurations... -> Find your applications configuration -> Go to (x) = Arguments Tab and add the above in the VM arguments text box. Surely it depends on how you start up your application. If you startup in a Unix box from command line, then the above arguments need to be in the command line. Or even better you can create a .launch file for your application. – nikkatsa Dec 21 '12 at 08:43
  • @nikkatsa Thanks I already add this in my local machine. Its works but i need to configure remote pc or other pc. – Sai Ye Yan Naing Aye Dec 21 '12 at 08:53
  • How to you start up your application in your remote machine ? Do you start from command line ? Is it a Unix box or a Windows one ? – nikkatsa Dec 21 '12 at 09:01
  • @nikkatsa please check my edit post. I test this on windows. – Sai Ye Yan Naing Aye Dec 21 '12 at 09:09
  • 1
    I would suggest if this window machine that you test it, is your remote machine to start the java application from command line like below `java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false YourApp.jar. ` In addition you can have a look at the below link, which explains how to do that in different app servers. [link](http://jremoterun.sourceforge.net/startingJmxConnector.html) – nikkatsa Dec 21 '12 at 09:34
  • You could look at this answer : http://stackoverflow.com/a/1780634/1197346 – Captain_spack_jarrow Jul 21 '15 at 21:12

0 Answers0