Class CircuitBreakerMetrics

java.lang.Object
io.github.resilience4j.circuitbreaker.internal.CircuitBreakerMetrics
All Implemented Interfaces:
CircuitBreaker.Metrics

class CircuitBreakerMetrics extends Object implements CircuitBreaker.Metrics
  • Field Details

    • metrics

      private final io.github.resilience4j.core.metrics.Metrics metrics
    • failureRateThreshold

      private final float failureRateThreshold
    • slowCallRateThreshold

      private final float slowCallRateThreshold
    • slowCallDurationThresholdInNanos

      private final long slowCallDurationThresholdInNanos
    • numberOfNotPermittedCalls

      private final LongAdder numberOfNotPermittedCalls
    • minimumNumberOfCalls

      private int minimumNumberOfCalls
  • Constructor Details

  • Method Details

    • forClosed

      static CircuitBreakerMetrics forClosed(CircuitBreakerConfig circuitBreakerConfig, Clock clock)
    • forHalfOpen

      static CircuitBreakerMetrics forHalfOpen(int permittedNumberOfCallsInHalfOpenState, CircuitBreakerConfig circuitBreakerConfig, Clock clock)
    • forForcedOpen

      static CircuitBreakerMetrics forForcedOpen(CircuitBreakerConfig circuitBreakerConfig, Clock clock)
    • forDisabled

      static CircuitBreakerMetrics forDisabled(CircuitBreakerConfig circuitBreakerConfig, Clock clock)
    • forMetricsOnly

      static CircuitBreakerMetrics forMetricsOnly(CircuitBreakerConfig circuitBreakerConfig, Clock clock)
    • onCallNotPermitted

      void onCallNotPermitted()
      Records a call which was not permitted, because the CircuitBreaker state is OPEN.
    • onSuccess

      public CircuitBreakerMetrics.Result onSuccess(long duration, TimeUnit durationUnit)
      Records a successful call and checks if the thresholds are exceeded.
      Returns:
      the result of the check
    • onError

      public CircuitBreakerMetrics.Result onError(long duration, TimeUnit durationUnit)
      Records a failed call and checks if the thresholds are exceeded.
      Returns:
      the result of the check
    • checkIfThresholdsExceeded

      private CircuitBreakerMetrics.Result checkIfThresholdsExceeded(io.github.resilience4j.core.metrics.Snapshot snapshot)
      Checks if the failure rate is above the threshold or if the slow calls percentage is above the threshold.
      Parameters:
      snapshot - a metrics snapshot
      Returns:
      false, if the thresholds haven't been exceeded.
    • getSlowCallRate

      private float getSlowCallRate(io.github.resilience4j.core.metrics.Snapshot snapshot)
    • getFailureRate

      private float getFailureRate(io.github.resilience4j.core.metrics.Snapshot snapshot)
    • getFailureRate

      public float getFailureRate()
      Returns the current failure rate in percentage. If the number of measured calls is below the minimum number of measured calls, it returns -1.
      Specified by:
      getFailureRate in interface CircuitBreaker.Metrics
      Returns:
      the failure rate in percentage
    • getSlowCallRate

      public float getSlowCallRate()
      Returns the current percentage of calls which were slower than a certain threshold. If the number of measured calls is below the minimum number of measured calls, it returns -1.
      Specified by:
      getSlowCallRate in interface CircuitBreaker.Metrics
      Returns:
      the failure rate in percentage
    • getNumberOfSuccessfulCalls

      public int getNumberOfSuccessfulCalls()
      Returns the current number of successful buffered calls in the ring buffer.
      Specified by:
      getNumberOfSuccessfulCalls in interface CircuitBreaker.Metrics
      Returns:
      the current number of successful buffered calls in the ring buffer
    • getNumberOfBufferedCalls

      public int getNumberOfBufferedCalls()
      Returns the current total number of buffered calls in the ring buffer.
      Specified by:
      getNumberOfBufferedCalls in interface CircuitBreaker.Metrics
      Returns:
      he current total number of buffered calls in the ring buffer
    • getNumberOfFailedCalls

      public int getNumberOfFailedCalls()
      Description copied from interface: CircuitBreaker.Metrics
      Returns the current number of failed buffered calls in the ring buffer.
      Specified by:
      getNumberOfFailedCalls in interface CircuitBreaker.Metrics
      Returns:
      the current number of failed buffered calls in the ring buffer
    • getNumberOfSlowCalls

      public int getNumberOfSlowCalls()
      Description copied from interface: CircuitBreaker.Metrics
      Returns the current total number of calls which were slower than a certain threshold.
      Specified by:
      getNumberOfSlowCalls in interface CircuitBreaker.Metrics
      Returns:
      the current total number of calls which were slower than a certain threshold
    • getNumberOfSlowSuccessfulCalls

      public int getNumberOfSlowSuccessfulCalls()
      Description copied from interface: CircuitBreaker.Metrics
      Returns the current number of successful calls which were slower than a certain threshold.
      Specified by:
      getNumberOfSlowSuccessfulCalls in interface CircuitBreaker.Metrics
      Returns:
      the current number of successful calls which were slower than a certain threshold
    • getNumberOfSlowFailedCalls

      public int getNumberOfSlowFailedCalls()
      Description copied from interface: CircuitBreaker.Metrics
      Returns the current number of failed calls which were slower than a certain threshold.
      Specified by:
      getNumberOfSlowFailedCalls in interface CircuitBreaker.Metrics
      Returns:
      the current number of failed calls which were slower than a certain threshold
    • getNumberOfNotPermittedCalls

      public long getNumberOfNotPermittedCalls()
      Returns the current number of not permitted calls, when the state is OPEN.

      The number of denied calls is always 0, when the CircuitBreaker state is CLOSED or HALF_OPEN. The number of denied calls is only increased when the CircuitBreaker state is OPEN.

      Specified by:
      getNumberOfNotPermittedCalls in interface CircuitBreaker.Metrics
      Returns:
      the current number of not permitted calls