0

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?

AKS
  • 1,393
  • 3
  • 19
  • 29

1 Answers1

1

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);
      }
Bruce T.
  • 992
  • 4
  • 5
  • Thanks Bruce! I will have to call this code using reflection as this code can be executed in different containers (TomCat,WebLogic,WebSphere) . So I will have to load it on conditions. – AKS Sep 18 '17 at 23:13
  • It will be even more fun when you turn on security ;-) – Bruce T. Sep 19 '17 at 00:25
  • Yes, you are right. With security ON, it gives "Caused by: com.ibm.websphere.management.exception.AdminException: com.ibm.websphere.management.exception.ConnectorNotAvailableException" – AKS Sep 19 '17 at 12:06
  • To do anything with the mbeans, the code has to run under the ID of an authenticated user that has permission to execute the mbean operations, similar to if they had logged in as a wsadmin user. But the connectorNotAvailable exception suggests the server just can't connect to the node agent or dmgr in a secured way, so that might be a setup issue. If you're just after topology info, there are ways to get that without requiring such privileges. – Bruce T. Sep 21 '17 at 23:29
  • Thanks! I am just looking for Topology info and I also want to use Garbage Collection Notification bean so that i can run collect all GC metrics when it is happening. – AKS Sep 24 '17 at 11:56
  • Well, I thought there was a way to do that without privileges but it's not jumping out at me now. QueryMbeans and QueryNames will run without privileges that gives you quite a bit of info about what the servers and clusters are and the nodes they are on, but not the cluster members. You can read the config data directly down in the config\cells\... tree, but that doesn't show you everything on the other nodes. The connectorNotAvailable exception might be due to not syncing and restarting everything after enabling security. – Bruce T. Sep 24 '17 at 18:50