webspherejmxmbeans

How to get Cluster nodes in Websphere using PlatformMbeanServer?


I have deployed one war application in WebSphere ,as part of Server1 and Server2 . There is a cluster which has these two servers. I want to write java code as part of my war application and fetch cluster node details.

  MBeanServer mbServer = ManagementFactory.getPlatformMBeanServer();
  Set mBeanSet = mbServer.queryMBeans(null, null);

Above code is not listing cluster mbean, In fact , not all the mbeans are getting listed here.

From Jconsole also, Cluster Mbean is not getting listed here.

Am i missing something?


Solution

  • WebSphere MBeans aren't in the same MBean server as the JVM Mbeans. Here's code to list all the WebSphere MBeans. Since the Cluster Mbean is on the Deployment Manager, we have to look there for it.

          ObjectName on = new ObjectName("WebSphere:*");          
          Set mbeans = AdminServiceFactory.getAdminService()
                  .getDeploymentManagerAdminClient().queryMBeans(on, null);
    
          for (Object o: mbeans){             
              System.out.println("mbean: "+ o);
          }