我在使用 jython 时遇到问题。当我使用 jython/python 脚本访问 MBean 时,我得到了打印的值,但我想解析结果,以便我可以提取必要的内容。
这是代码和输出:
def get_attribute(mbean,attribute):
#<domain>:type=<type>
obn = javax.management.ObjectName(mbean)
#<attribute> ie: HeapMemoryUsage
return remote.getAttribute(obn, attribute)
print get_attribute("java.lang:type=Memory","HeapMemoryUsage")
文本输出为:
javax.management.openmbean.CompositeDataSupport(compositeType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java. lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java. lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=61276160, init=63313088, max=129761280, used= 30232944})
如果有人能给我一些例子或想法,那就太好了。
非常感谢。
以 Jython 为例,如果你想获取一个 MBean 的信息,那么很容易调用:
print remote.getMBeanInfo(ObjectName("java.lang:type=Memory"))
但同样,输出是这样的:
javax.management.MBeanInfo[description=Information on the management interface of the MBean, attributes=[javax.management.MBeanAttributeInfo[description=Verbose, name=Verbose, type=boolean, read/write, isIs, descriptor={openType=javax.management.openmbean.SimpleType(name=java.lang.Boolean), originalType=boolean}], javax.management.openmbean.OpenMBeanAttributeInfoSupport(name=HeapMemoryUsage,openType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),default=null,minValue=null,maxValue=null,legalValues=null,descriptor={openType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))), originalType=java.lang.management.MemoryUsage}), javax.management.MBeanAttributeInfo[description=ObjectPendingFinalizationCount, name=ObjectPendingFinalizationCount, type=int, read-only, descriptor={openType=javax.management.openmbean.SimpleType(name=java.lang.Integer), originalType=int}], javax.management.openmbean.OpenMBeanAttributeInfoSupport(name=NonHeapMemoryUsage,openType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),default=null,minValue=null,maxValue=null,legalValues=null,descriptor={openType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))), originalType=java.lang.management.MemoryUsage}), javax.management.openmbean.OpenMBeanAttributeInfoSupport(name=ObjectName,openType=javax.management.openmbean.SimpleType(name=javax.management.ObjectName),default=null,minValue=null,maxValue=null,legalValues=null,descriptor={openType=javax.management.openmbean.SimpleType(name=javax.management.ObjectName), originalType=javax.management.ObjectName})], constructors=[], operations=[javax.management.MBeanOperationInfo[description=gc, name=gc, returnType=void, signature=[], impact=unknown, descriptor={openType=javax.management.openmbean.SimpleType(name=java.lang.Void), originalType=void}]], notifications=[javax.management.MBeanNotificationInfo[description=Memory Notification, name=javax.management.Notification, notifTypes=[java.management.memory.threshold.exceeded, java.management.memory.collection.threshold.exceeded], descriptor={}]], descriptor={immutableInfo=true, interfaceClassName=java.lang.management.MemoryMXBean, mxbean=true}]
因此,如果有人知道将这些输出解析为某个对象以获得漂亮显示的好方法,请发表评论。
非常感谢。