Search This Blog

Monday 7 November 2011

Viewing All MBeans for a GemFire Cluster

In order to view all the MBeans available in a GemFire cluster you could write a simple console client application as follows. This will extract all the MBeans by name and hence work out which one you want to take a look at.

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)-32249/50418,type=IndexStats,name=ownerIdx,uid=130
-> GemFire.Statistic:source=10.117.85.62(23883)-32249/50418,type=IndexStats,name=ownerIdx,uid=131
-> GemFire.Statistic:source=10.117.85.62(23883)-32249/50418,type=IndexStats,name=ownerIdx,uid=132
-> GemFire.Statistic:source=10.117.85.62(23883)-32249/50418,type=IndexStats,name=ownerIdx,uid=133
-> GemFire.Statistic:source=10.117.85.62(23883)-32249/50418,type=IndexStats,name=ownerIdx,uid=134
-> GemFire.Statistic:source=10.117.85.62(23883)-32249/50418,type=IndexStats,name=ownerIdx,uid=135
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=115
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=116
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=113
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=114
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=111
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=112
-> GemFire.Statistic:source=10.117.85.62(23883)-32249/50418,type=DLockStats,name=dlockStats,uid=18
-> connectors:protocol=rmi
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=110
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=119
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=117
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=118
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=VMMemoryPoolStats,name=Par Eden Space-Heap memory,uid=7
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=DiskRegionStatistics,name=/AllObjectRegion,uid=20
-> GemFire:type=MemberInfoWithStatsMBean
-> GemFire.Cache:name=default,id=1558631662,owner=10.117.85.62(23876)-41281/50410,type=Cache
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=DLockStats,name=dlockStats,uid=18
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=VMStats,name=vmStats,uid=3
-> GemFire.Statistic:source=10.117.85.62(23876)-41281/50410,type=IndexStats,name=ownerIdx,uid=102

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: