On a Linux machine, I have an existing third-party Java application. I can find out the status of the application in real time by going to the / proc / PID / directory (memory, thread, etc.). However, I want to run a separate Java program on the same computer to do this without using JConsole or VisualVM (like a production environment). I was looking for a theme for JMX. However, it only returns information about its own program, and not about a third-party application that I am trying to control. I'm right? Is there a way to do this (other than parsing / proc / PID / result)? Thanks!
Follow the recommendations, I wrote a simple program for the local monitor. However, I got the following error. Any idea?
String hostName = "xx.xx.xx.xx";
int portNum = xxxx;
try {
JMXServiceURL u = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + hostName + ":" + portNum + "/jmxrmi");
JMXConnector c = JMXConnectorFactory.connect(u);
}
catch (Exception e) {
e.printStackTrace();
}
------Output------
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: jmxrmi
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:207)
at test.main(test.java:57)
Caused by: javax.naming.NameNotFoundException: jmxrmi
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:99)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:255)
... 3 more