简体   繁体   English

如何查询伺服MBean的Hystrix?

[英]How to query the servo MBean for Hystrix?

I am able to access the MBeans in JConsole, and they show up like com.netflix.servo > HystrixCommand > countSuccess > (actual commands and their attributes) 我能够在JConsole中访问MBean,并且它们显示为com.netflix.servo > HystrixCommand > countSuccess >(实际命令及其属性)

I couldn't find any examples on how to query these objects and the values, eg the countSuccess, countFailure etc. 我找不到有关如何查询这些对象和值的任何示例,例如countSuccess,countFailure等。

The closest I came was ObjectName o = new ObjectName("com.netflix.servo:name=countSuccess,instance=T6JmxStatCommand,type=HystrixCommand"); 我最接近的是ObjectName o = new ObjectName("com.netflix.servo:name=countSuccess,instance=T6JmxStatCommand,type=HystrixCommand"); which is at https://github.com/n0rad/hands-on-hystrix/blob/master/src/test/java/fr/n0rad/hands/on/hystrix/t6/T6JmxStatMain.java but apparently it doesn't work. 它位于https://github.com/n0rad/hands-on-hystrix/blob/master/src/test/java/fr/n0rad/hands/on/hystrix/t6/T6JmxStatMain.java,但显然不是工作。

The mbeans were registered via this code: HystrixPlugins.getInstance().registerMetricsPublisher(HystrixServoMetricsPublisher.getInstance()); 通过以下代码HystrixPlugins.getInstance().registerMetricsPublisher(HystrixServoMetricsPublisher.getInstance());HystrixPlugins.getInstance().registerMetricsPublisher(HystrixServoMetricsPublisher.getInstance());

Found out there was nothing wrong with the object name as queried. 发现所查询的对象名称没有问题。 In fact it is the same one found in the JConsole; 实际上,它与JConsole中的相同。 full syntax shown here on the right in the screenshot: 屏幕截图的右侧显示了完整的语法: 在此处输入图片说明

Plus, I needed to add a few system properties to the Eclipse run configuration: -Dcom.sun.management.jmxremote.rmi.port=8700 -Dcom.sun.management.jmxremote.port=8600 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false 另外,我需要向Eclipse运行配置中添加一些系统属性: -Dcom.sun.management.jmxremote.rmi.port=8700 -Dcom.sun.management.jmxremote.port=8600 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

Then I can connect using port 8600. In code: 然后,我可以使用端口8600进行连接。在代码中:

package com.awgtek.miscpocs.lognfetch.client;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class TestJMXConn {

    public static void main(String[] args) throws Exception {
      JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8600/jmxrmi");
      JMXConnector connect = JMXConnectorFactory.connect(url);
      MBeanServerConnection mbsc = connect.getMBeanServerConnection();
     // ObjectName o = new ObjectName("com.netflix.servo:name=countSuccess,type=HystrixCommand,instance=LogAndFetchRestServicePostCommand");
      ObjectName o = new ObjectName("com.netflix.servo:name=countSuccess,type=HystrixCommand,instance=LogAndFetchRestServiceGetCommand");
      Object value = mbsc.getAttribute(o, "value");
      System.out.println("the value: " + value);
      connect.close();


    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM