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"));
      }
  }
6
  • 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, 2012 at 8:43
  • @nikkatsa Thanks I already add this in my local machine. Its works but i need to configure remote pc or other pc. Dec 21, 2012 at 8: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, 2012 at 9:01
  • @nikkatsa please check my edit post. I test this on windows. Dec 21, 2012 at 9: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
    – nikkatsa
    Dec 21, 2012 at 9:34

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.