我正在实现一个servlet作为JMX管理器,该JMX管理器运行在Tomcat的相同实例中,以便运行所有受监控的servlet。当我打开JConsole时,可以看到受监控servlet的数据。从我的经理servlet中我可以枚举所有可用标准的MBean,包括我在监控的servlet中创建的,使用这样的代码:如何通过MBean获取数据
JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://localhost:1099/jndi/rmi://localhost:1099/jmxrmi");
mConnector = JMXConnectorFactory.connect(url);
mMBSC = mConnector.getMBeanServerConnection();
mObjectName = new ObjectName("com.blahCompany.blah.blah:type=BlahBlah");
// just looking for one specific bean
Set<ObjectName> myMbean = mMBSC.queryNames(mObjectName, null);
if(myMBean.size() == 1) // I know it exists
{
MBeanInfo mbeanInfo = mMBSC.getMBeanInfo(<ObjectName extracted from Set>);
MBeanAttributeInfo[] mbeanAttributeInfos = mbeanInfo.getAttributes();
for(MBeanAttributeInfo attribInfo : mbeanAttributeInfos)
{
if(attribInfo.isReadable())
{
String attribName = attribInfo.getName();
String attribReturnType = attribInfo.getType();
// The data's somewhere ... where????
// In the MBeanInfo?
// In the MBeanAttributeInfo??
}
}
}
的问题是我不知道如何实际上从这些MBean中提取数据。答案一定是明显的,因为其他人似乎没有问过,但我确实有一个礼物可以忽略这些明显的问题。感谢您的帮助。
比尔
我更新了我的回答,提供了关于本地访问mbean服务器的说明,从我的问题中了解到您的情况需要什么(无需通过URL进行连接)。我认为性能会比使用远程连接更好。 – 2012-03-05 21:22:03