gpt4 book ai didi

jboss - 获取 mbean 属性值?

转载 作者:行者123 更新时间:2023-12-02 05:44:45 25 4
gpt4 key购买 nike

我被困在这里了:

我需要获取的值

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com