Hystrix: Latency and Fault Tolerance for Distributed Systems



com.netflix.hystrix
Class HystrixCommandMetrics

java.lang.Object
  extended by com.netflix.hystrix.HystrixCommandMetrics

public class HystrixCommandMetrics
extends java.lang.Object

Used by HystrixCommand to record metrics.


Nested Class Summary
static class HystrixCommandMetrics.HealthCounts
          Number of requests during rolling window.
 
Method Summary
 HystrixCommandGroupKey getCommandGroup()
          HystrixCommandGroupKey of the HystrixCommand these metrics represent.
 HystrixCommandKey getCommandKey()
          HystrixCommandKey these metrics represent.
 long getCumulativeCount(HystrixRollingNumberEvent event)
          Get the cumulative count since the start of the application for the given HystrixRollingNumberEvent.
 int getCurrentConcurrentExecutionCount()
          Current number of concurrent executions of HystrixCommand.run();
 int getExecutionTimeMean()
          The mean (average) execution time (in milliseconds) for the HystrixCommand.run().
 int getExecutionTimePercentile(double percentile)
          Retrieve the execution time (in milliseconds) for the HystrixCommand.run() method being invoked at a given percentile.
 HystrixCommandMetrics.HealthCounts getHealthCounts()
          Retrieve a snapshot of total requests, error count and error percentage.
static HystrixCommandMetrics getInstance(HystrixCommandKey key)
          Get the HystrixCommandMetrics instance for a given HystrixCommandKey or null if one does not exist.
static HystrixCommandMetrics getInstance(HystrixCommandKey key, HystrixCommandGroupKey commandGroup, HystrixCommandProperties properties)
          Get or create the HystrixCommandMetrics instance for a given HystrixCommandKey.
static java.util.Collection<HystrixCommandMetrics> getInstances()
          All registered instances of HystrixCommandMetrics
 HystrixCommandProperties getProperties()
          HystrixCommandProperties of the HystrixCommand these metrics represent.
 long getRollingCount(HystrixRollingNumberEvent event)
          Get the rolling count for the given HystrixRollingNumberEvent.
 int getTotalTimeMean()
          The mean (average) execution time (in milliseconds) for HystrixCommand.execute() or HystrixCommand.queue().
 int getTotalTimePercentile(double percentile)
          Retrieve the total end-to-end execution time (in milliseconds) for HystrixCommand.execute() or HystrixCommand.queue() at a given percentile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static HystrixCommandMetrics getInstance(HystrixCommandKey key,
                                                HystrixCommandGroupKey commandGroup,
                                                HystrixCommandProperties properties)
Get or create the HystrixCommandMetrics instance for a given HystrixCommandKey.

This is thread-safe and ensures only 1 HystrixCommandMetrics per HystrixCommandKey.

Parameters:
key - HystrixCommandKey of HystrixCommand instance requesting the HystrixCommandMetrics
commandGroup - Pass-thru to HystrixCommandMetrics instance on first time when constructed
properties - Pass-thru to HystrixCommandMetrics instance on first time when constructed
Returns:
HystrixCommandMetrics

getInstance

public static HystrixCommandMetrics getInstance(HystrixCommandKey key)
Get the HystrixCommandMetrics instance for a given HystrixCommandKey or null if one does not exist.

Parameters:
key - HystrixCommandKey of HystrixCommand instance requesting the HystrixCommandMetrics
Returns:
HystrixCommandMetrics

getInstances

public static java.util.Collection<HystrixCommandMetrics> getInstances()
All registered instances of HystrixCommandMetrics

Returns:
Collection<HystrixCommandMetrics>

getCommandKey

public HystrixCommandKey getCommandKey()
HystrixCommandKey these metrics represent.

Returns:
HystrixCommandKey

getCommandGroup

public HystrixCommandGroupKey getCommandGroup()
HystrixCommandGroupKey of the HystrixCommand these metrics represent.

Returns:
HystrixCommandGroupKey

getProperties

public HystrixCommandProperties getProperties()
HystrixCommandProperties of the HystrixCommand these metrics represent.

Returns:
HystrixCommandProperties

getCumulativeCount

public long getCumulativeCount(HystrixRollingNumberEvent event)
Get the cumulative count since the start of the application for the given HystrixRollingNumberEvent.

Parameters:
event - HystrixRollingNumberEvent of the event to retrieve a sum for
Returns:
long cumulative count

getRollingCount

public long getRollingCount(HystrixRollingNumberEvent event)
Get the rolling count for the given HystrixRollingNumberEvent.

The rolling window is defined by HystrixCommandProperties.metricsRollingStatisticalWindowInMilliseconds().

Parameters:
event - HystrixRollingNumberEvent of the event to retrieve a sum for
Returns:
long rolling count

getExecutionTimePercentile

public int getExecutionTimePercentile(double percentile)
Retrieve the execution time (in milliseconds) for the HystrixCommand.run() method being invoked at a given percentile.

Percentile capture and calculation is configured via HystrixCommandProperties.metricsRollingStatisticalWindowInMilliseconds() and other related properties.

Parameters:
percentile - Percentile such as 50, 99, or 99.5.
Returns:
int time in milliseconds

getExecutionTimeMean

public int getExecutionTimeMean()
The mean (average) execution time (in milliseconds) for the HystrixCommand.run().

This uses the same backing data as HystrixCommandMetrics.getExecutionTimePercentile(double);

Returns:
int time in milliseconds

getTotalTimePercentile

public int getTotalTimePercentile(double percentile)
Retrieve the total end-to-end execution time (in milliseconds) for HystrixCommand.execute() or HystrixCommand.queue() at a given percentile.

When execution is successful this would include time from HystrixCommandMetrics.getExecutionTimePercentile(double) but when execution is being rejected, short-circuited, or timed-out then the time will differ.

This time can be lower than HystrixCommandMetrics.getExecutionTimePercentile(double) when a timeout occurs and the backing thread that calls HystrixCommand.run() is still running.

When rejections or short-circuits occur then HystrixCommand.run() will not be executed and thus not contribute time to HystrixCommandMetrics.getExecutionTimePercentile(double) but time will still show up in this metric for the end-to-end time.

This metric gives visibility into the total cost of HystrixCommand execution including the overhead of queuing, executing and waiting for a thread to invoke HystrixCommand.run() .

Percentile capture and calculation is configured via HystrixCommandProperties.metricsRollingStatisticalWindowInMilliseconds() and other related properties.

Parameters:
percentile - Percentile such as 50, 99, or 99.5.
Returns:
int time in milliseconds

getTotalTimeMean

public int getTotalTimeMean()
The mean (average) execution time (in milliseconds) for HystrixCommand.execute() or HystrixCommand.queue().

This uses the same backing data as HystrixCommandMetrics.getTotalTimePercentile(double);

Returns:
int time in milliseconds

getCurrentConcurrentExecutionCount

public int getCurrentConcurrentExecutionCount()
Current number of concurrent executions of HystrixCommand.run();

Returns:
int

getHealthCounts

public HystrixCommandMetrics.HealthCounts getHealthCounts()
Retrieve a snapshot of total requests, error count and error percentage.

Returns:
HystrixCommandMetrics.HealthCounts