arthas提供Mbean命令查看或监控 Mbean 的属性信息。
MBeanServer是一个包含所有注册MBean的仓库.它是JMX代理层的核心.JMX1.0规范提供一个接口叫 javax.management.MBeanServer. 所有管理的在MBean操作通过MBeanServer执行.使用MBeanServer实例,你能够管理所有MBean.每一个MBean具有一个唯一标志,叫ObjectName.
private Set<ObjectName> queryObjectNames() {
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = new HashSet<ObjectName>();
try {
if (StringUtils.isEmpty(name)) {
name = "*:*";
}
objectNames = platformMBeanServer.queryNames(new ObjectName(name), null);
} catch (MalformedObjectNameException e) {
logger.warn("queryObjectNames error", e);
}
return objectNames;
}
private void listMetaData(CommandProcess process) {
Set<ObjectName> objectNames = queryObjectNames();
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
MBeanModel mbeanModel = new MBeanModel();
Map<String, MBeanInfo> mbeanMetaData = new LinkedHashMap<String, MBeanInfo>();
mbeanModel.setMbeanMetadata(mbeanMetaData);
for (ObjectName objectName : objectNames) {
MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName);
mbeanMetaData.put(objectName.toString(), mBeanInfo);
}
process.appendResult(mbeanModel);
process.end();
} catch (Throwable e) {
logger.warn("listMetaData error", e);
process.end(1, "list mbean metadata error");
}
}
通过 ManagementFactory.getPlatformMBeanServer()获取MBeanServer。
通过MBeanServer的queryNames获取ObjectName对象。
通过MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName)获取MBeanInfo
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/qq_21383435/article/details/123975027
内容来源于网络,如有侵权,请联系作者删除!