【问题标题】:Why am I not getting hystrix metrics?为什么我没有得到 hystrix 指标?
【发布时间】:2015-11-26 09:37:04
【问题描述】:

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

我通过实现(有点)RESTful 接口来模拟网络调用,该接口返回 pow 计算:

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

这就是我调用 hystrix 命令并期望获得一些指标的方式(至少 Requests: not 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();
}

【问题讨论】:

  • 我可能有一个解决方案:我认为拨打GetPowerCommand.run() 是错误的。我应该打电话给GetPowerCommand.execute()。

标签: java spring-boot monitoring netflix hystrix


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-01-05
    • 1970-01-01
    • 2020-11-19
    • 2013-07-15
    • 2015-06-03
    • 1970-01-01
    • 2013-09-06
    • 2020-01-25
    • 2023-03-06
    相关资源
    最近更新 更多