1. First we need to start a JMX agent. The JMX Agent can be run as a separate, “invisible” distributed system member, or it can be collocated in an application. The JMX Agent manages only a single distributed system.
Here we use a located to join the distributed system
> agent start -J-Xmx550m -dir=agent mcast-port=0 locators=localhost[41111]
2. By default the JMX service URL is as follows
service:jmx:rmi://{agent-host}/jndi/rmi://:{agent-port}/jmxconnector
3. Write a Java Client as follows
package pas.au.gemfire.jmx; import java.io.IOException; import java.net.MalformedURLException; import java.util.Set; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; public class ShowAllMBeans { /** The JMX client connector */ private JMXConnector jmxConnector; /** The JMX MBean server connection */ private MBeanServerConnection mbs; public void run() { String urlString = "service:jmx:rmi://localhost/jndi/rmi://:1099/jmxconnector"; JMXServiceURL url = null; try { url = new JMXServiceURL(urlString); jmxConnector = JMXConnectorFactory.connect(url); mbs = jmxConnector.getMBeanServerConnection(); // show all MBeans here... Set<ObjectName> mbeans = mbs.queryNames(null, null); System.out.println(mbeans.size() + " MBeans found\n"); for (ObjectName mbeanName : mbeans) { System.out.println("-> " + mbeanName); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { disconnectFromAgent(); } System.out.println("all done..."); } private void disconnectFromAgent() { if(this.jmxConnector != null) { try { this.jmxConnector.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ShowAllMBeans test = new ShowAllMBeans(); test.run(); } }
4. Output as follows
292 MBeans found
-> GemFire.Statistic:source=10.117.85.62(23883)
-> GemFire.Statistic:source=10.117.85.62(23883)
-> GemFire.Statistic:source=10.117.85.62(23883)
-> GemFire.Statistic:source=10.117.85.62(23883)
-> GemFire.Statistic:source=10.117.85.62(23883)
-> GemFire.Statistic:source=10.117.85.62(23883)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23883)
-> connectors:protocol=rmi
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire:type=MemberInfoWithStatsMBean
-> GemFire.Cache:name=default,id=1558631662,owner=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
-> GemFire.Statistic:source=10.117.85.62(23876)
For more information on using JMX to administer GemFire see the link below.
http://www.gemstone.com/docs/html/gemfire/6.0.0/SystemAdministratorsGuide/JMX.9.1.html
No comments:
Post a Comment