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

时间:2015-09-01 08:14:55

标签: java spring-boot monitoring netflix hystrix

我正在尝试使用hystrix来监控某个网络呼叫。但我试图监控的所有指标总是空的。我做错了什么?

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

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

这就是我调用hystrix命令并期望得到一些指标(至少请求:不是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();
}

1 个答案:

答案 0 :(得分:1)

您已回答了问题:使用execute()代替run()。看看here