jboss - 获取 mbean 属性值?

标签 jboss attributes jmx mbeans

我被困在这里:

我需要获取的值

org.jboss.system.server.ServerInfo

通过这里的代码,我正在读取 mbean 属性, 但我只能找到 .hashvalues,而不是值!

final MBeanAttributeInfo[] attributes = server.getMBeanInfo(mbean).getAttributes();
for (final MBeanAttributeInfo attribute : attributes) {
                    String name = attribute.getName();                            
}

经过两天的寻找 我请求帮助!

非常感谢,罗曼。

最佳答案

public static Map<String, Object> getAllAttributes(String host, int port, String mbeanName) throws MalformedObjectNameException, IOException, InstanceNotFoundException, IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException {
    // Get JMX connector and get MBean server connection
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi");
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();       

    // Query all attributes and values
    ObjectName name = new ObjectName(mbeanName);
    MBeanInfo info = mbsc.getMBeanInfo(name);
    MBeanAttributeInfo[] attrInfo = info.getAttributes();
    Map<String, Object> map = new HashMap<>();
    for (MBeanAttributeInfo attr : attrInfo) {
        if (attr.isReadable()) {
            //System.out.println("\t" + attr.getName() + " = " + mbsc.getAttribute(name, attr.getName()));
            map.put(attr.getName(), mbsc.getAttribute(name, attr.getName()));
            }
        }
    jmxc.close();
    return map;

}

关于jboss - 获取 mbean 属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10425690/

相关文章:

java - 如何从另一台计算机访问 WildFly 12 服务器上的 Web 应用程序?

c# - 我可以从自定义 JsonConverter 的 WriteJson 方法获取属性的属性吗?

eclipse - 使用 JMX 监控 Tomcat 服务器的简单工具

powershell - 如何在Windows Server 2012(AWS EC2)中更改和验证主机名

jboss - 无法在 Drools Workbench 中使用 docker-compose "see"KIE 服务器

java - 从 Eclipse 远程调试服务器 Jboss eap 6.4 失败

java - JPA+ hibernate : Change of createNativeQuery() + getResultList() behaviour?

python - 无法让 NetworkX 读取我的加权网络(+尚未找到从文件导入节点属性的方法)

c# - 将类的属性映射到接口(interface)

java - 如何在我的 JVM 上激活 JMX 以使用 jconsole 进行访问?