Rom*_*man 2 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();
}
Run Code Online (Sandbox Code Playgroud)
经过两天的搜索,我请求帮助!
非常感谢,罗曼。
小智 5
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7917 次 |
| 最近记录: |