1

I am trying to use hystrix to monitor a certain network call. But all the metrics I try to monitor are always empty. What am I doing wrong?

I simulate a network call by implementing a (somewhat) RESTful interface that returns a pow calculation:

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

This is how I call the hystrix command and expect to get some metrics (at least 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));
}

But all I get is:

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 

edit: my metrics retrieval method:

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();
}
4

1 回答 1

1

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

于 2015-09-01T19:41:19.093 回答