I am running a client/server application using JBoss.
How can I connect to the server JVM's MBeanServer? I want to use the MemoryMX MBean to track the memory consumption.
I can connect to the JBoss MBeanServer using JNDI lookup but the java.lang.MemoryMX MBean is not registered with the JBoss MBeanServer.
EDIT: The requirement is for programmatic access to the memory usage from the client.
A code example from an IBM article: link
The following code lists all mbeans of a given (jmx enabled) java application with their attributes and operations grouped by the domain. Just start the java app you wanna monitor with a fixed jmx port, e.g. by using these vm parameters:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9000
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
Then run this main:
As you should see, in the java.lang domain are several memory related mbeans. Pick the one you need.
I wrote a class like this:
Unlike the JBoss server's MBeanServer, the JVM's MBean server doesn't allow remote monitoring by default. You need to set various system properties to allow that:
http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
Have you tried launching a
JConsole
(is$JAVA_HOME/bin
) to connect with the server? You should be able to view memory stats from there