我正在尝试通过jmx特别是getMBeanServerConnection访问MBean值。 jconsole中的树设置很难遍历,我需要一些帮助来获取我特别需要的值,或者能够获取所有类型,名称和属性。这是我用来读取jmx mbean值的内容:
//get an instance of the kafka metrics Mbean
consumerBeanII =
jmxCon.getMBeanServerConnection().getAttribute(new
ObjectName("kafka.server:type=BrokerTopicMetrics,
name=MessagesInPerSec,topic=data.in"),"MeanRate");
System.out.println(" Message Mean Rate: " + consumerBeanII);
// this works
consumerBean = jmxCon.getMBeanServerConnection().getAttribute(new
ObjectName("kafka.server:type=FetcherLagMetrics,
name=ConsumerLag,side=ReplicaFetcherThread-0-
2,topic=data.in"),"Value");
System.out.println(" ConsumerLag: " + consumerBean);
//this does not work and throws exception
错误:
javax.management.InstanceNotFoundException:
kafka.server:type=FetcherLagMetrics,name=ConsumerLag,
side=ReplicaFetcherThread-0-2,topic=data.in
现在这是jconsole树和层次结构的快照:
所以基本上如下:
kafka.server ---> FetcherLagMetrics --> ConsumerLag --->
ReplicaFetcherThread-0-2 ---> data.in ---> 5 ---> Attributes --->
Value
在ConsumerLag(ReplicateFetcherThread。*)下有多个子文件夹,然后在每个文件夹下都有所有主题。但是似乎所有值都为0,无论如何这都是一个单独的问题。任何建议或帮助表示赞赏