【问题标题】:How to get Cluster nodes in Websphere using PlatformMbeanServer?如何使用 PlatformMbeanServer 在 Websphere 中获取集群节点?
【发布时间】:2017-09-17 12:31:46
【问题描述】:

我在 WebSphere 中部署了一个 war 应用程序,作为 Server1 和 Server2 的一部分。 有一个具有这两个服务器的集群。 我想编写 java 代码作为我的 war 应用程序的一部分并获取集群节点详细信息。

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

上面的代码没有列出集群 mbean,事实上,并不是所有的 mbean 都在这里列出。

同样来自 Jconsole,此处未列出 Cluster Mbean。

我错过了什么吗?

【问题讨论】:

    标签: websphere jmx mbeans


    【解决方案1】:

    WebSphere MBean 与 JVM Mbean 不在同一个 MBean 服务器中。下面是列出所有 WebSphere MBean 的代码。由于 Cluster Mbean 在 Deployment Manager 上,我们必须在那里寻找它。

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

    【讨论】:

    • 谢谢布鲁斯!我将不得不使用反射调用此代码,因为此代码可以在不同的容器(TomCat、WebLogic、WebSphere)中执行。所以我必须根据条件加载它。
    • 开启安全功能会更有趣 ;-)
    • 是的,你是对的。启用安全性后,它会给出“由:com.ibm.websphere.management.exception.AdminException:com.ibm.websphere.management.exception.ConnectorNotAvailableException 引起”
    • 要对 mbean 进行任何操作,代码必须在有权执行 mbean 操作的经过身份验证的用户的 ID 下运行,类似于他们以 wsadmin 用户身份登录的情况。但是 connectorNotAvailable 异常表明服务器无法以安全的方式连接到节点代理或 dmgr,因此这可能是设置问题。如果您只是在获取拓扑信息,则有一些方法可以在不需要此类权限的情况下获得它。
    • 谢谢!我只是在寻找拓扑信息,我还想使用垃圾收集通知 bean,以便在它发生时运行收集所有 GC 指标。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-08
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    相关资源
    最近更新 更多