I\'m looking for sample Java JMX code to access the values of JMX attributes from another VM.
With JConsole, I have no problem looking at java.lang/Memory/Attributes
@Kire's answer looks good but I thought I'd add some details about my SimpleJMX package. It contains server support that allows you to export beans easily and also includes a simple client interface that works against any JVM that exports JMX information.
To access memory usage you'd do something like:
JmxClient client = new JmxClient("some.host.name", somePortNumber);
// get the memory composite information
CompositeData composite =
(CompositeData)client.getAttribute(new ObjectName("java.lang:type=Memory"),
"HeapMemoryUsage");
System.out.println(composite.get("committed"));