java - 为什么我没有获得 hystrix 指标?

标签 java spring-boot monitoring netflix hystrix

我正在尝试使用 hystrix 来监控某个网络调用。但我尝试监控的所有指标始终为空。我做错了什么?

我通过实现一个(某种程度上)RESTful 接口(interface)来模拟网络调用,该接口(interface)返回 pow 计算:

GetPowerCommand gpc = new GetPowerCommand(5, 82);
powerMetrics = gpc.getMetrics();

这就是我调用 hystrix 命令并期望获得一些指标的方式(至少 Requests:不是 0)

boolean run = true;
while (run) {
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
        run = false;
    }
    System.out.println("GetPowerCommand.run(): " + gpc.run());
    System.out.println("GetPowerCommand.run(): " + gpc.run());
    System.out.println("getStatsStringFromMetrics(powerMetrics): " + getStatsStringFromMetrics(powerMetrics));
}

但我得到的是:

GetPowerCommand.run(): <p>I guess .. </p><p>2^5 = 32</p>
GetPowerCommand.run(): <p>I guess .. </p><p>2^5 = 32</p>
getStatsStringFromMetrics(powerMetrics): Requests: 0 Errors: 0 (0%)   Mean: 0 50th: 0 75th: 0 90th: 0 99th: 0 
GetPowerCommand.run(): <p>I guess .. </p><p>2^5 = 32</p>
GetPowerCommand.run(): <p>I guess .. </p><p>2^5 = 32</p>
getStatsStringFromMetrics(powerMetrics): Requests: 0 Errors: 0 (0%)   Mean: 0 50th: 0 75th: 0 90th: 0 99th: 0 

编辑:我的指标检索方法:

private static String getStatsStringFromMetrics(HystrixCommandMetrics metrics) {
    StringBuilder m = new StringBuilder();
    if (metrics != null) {
        HealthCounts health = metrics.getHealthCounts();
        m.append("Requests: ").append(health.getTotalRequests()).append(" ");
        m.append("Errors: ").append(health.getErrorCount()).append(" (").append(health.getErrorPercentage())
                .append("%)   ");
        m.append("Mean: ").append(metrics.getTotalTimeMean()).append(" ");
        m.append("50th: ").append(metrics.getExecutionTimePercentile(50)).append(" ");
        m.append("75th: ").append(metrics.getExecutionTimePercentile(75)).append(" ");
        m.append("90th: ").append(metrics.getExecutionTimePercentile(90)).append(" ");
        m.append("99th: ").append(metrics.getExecutionTimePercentile(99)).append(" ");
    }
    return m.toString();
}

最佳答案

您已经回答了您的问题:使用 execute() 而不是 run()。也看看here

关于java - 为什么我没有获得 hystrix 指标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32326709/

相关文章:

netbeans - 在 Windows 8 中安装 Netbean 时出错

java - 考虑在您的配置中定义类型为 'org.springframework.data.mongodb.core.MongoTemplate' 的 bean

cookies - Spring Cloud Zuul 不转发 cookie

linux - 将顶级数据导出到文件

javascript - 错误监控缩小的 javascript

java - 在 Java 中设置 JTable 中的列宽

java - 在 Android 中从 JSON 对象对 JSON 数组进行排序?

java - org.hibernate.engine.jdbc.spi.SqlExceptionHelper - 找不到函数 "WITHIN"; SQL语句

linux - 如何在 Zabbix Server 中添加特定的 Windows 服务以通过电子邮件警报进行监控?

java - 基于Swing的应用架构