Class CircuitBreakerMetrics
java.lang.Object
io.github.resilience4j.circuitbreaker.internal.CircuitBreakerMetrics
- All Implemented Interfaces:
CircuitBreaker.Metrics
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final floatprivate final io.github.resilience4j.core.metrics.Metricsprivate intprivate final LongAdderprivate final longprivate final float -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateCircuitBreakerMetrics(int slidingWindowSize, CircuitBreakerConfig.SlidingWindowType slidingWindowType, CircuitBreakerConfig circuitBreakerConfig, Clock clock) privateCircuitBreakerMetrics(int slidingWindowSize, CircuitBreakerConfig circuitBreakerConfig, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionprivate CircuitBreakerMetrics.ResultcheckIfThresholdsExceeded(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.(package private) static CircuitBreakerMetricsforClosed(CircuitBreakerConfig circuitBreakerConfig, Clock clock) (package private) static CircuitBreakerMetricsforDisabled(CircuitBreakerConfig circuitBreakerConfig, Clock clock) (package private) static CircuitBreakerMetricsforForcedOpen(CircuitBreakerConfig circuitBreakerConfig, Clock clock) (package private) static CircuitBreakerMetricsforHalfOpen(int permittedNumberOfCallsInHalfOpenState, CircuitBreakerConfig circuitBreakerConfig, Clock clock) (package private) static CircuitBreakerMetricsforMetricsOnly(CircuitBreakerConfig circuitBreakerConfig, Clock clock) floatReturns the current failure rate in percentage.private floatgetFailureRate(io.github.resilience4j.core.metrics.Snapshot snapshot) intReturns the current total number of buffered calls in the ring buffer.intReturns the current number of failed buffered calls in the ring buffer.longReturns the current number of not permitted calls, when the state is OPEN.intReturns the current total number of calls which were slower than a certain threshold.intReturns the current number of failed calls which were slower than a certain threshold.intReturns the current number of successful calls which were slower than a certain threshold.intReturns the current number of successful buffered calls in the ring buffer.floatReturns the current percentage of calls which were slower than a certain threshold.private floatgetSlowCallRate(io.github.resilience4j.core.metrics.Snapshot snapshot) (package private) voidRecords a call which was not permitted, because the CircuitBreaker state is OPEN.Records a failed call and checks if the thresholds are exceeded.Records a successful call and checks if the thresholds are exceeded.
-
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
-
minimumNumberOfCalls
private int minimumNumberOfCalls
-
-
Constructor Details
-
CircuitBreakerMetrics
private CircuitBreakerMetrics(int slidingWindowSize, CircuitBreakerConfig.SlidingWindowType slidingWindowType, CircuitBreakerConfig circuitBreakerConfig, Clock clock) -
CircuitBreakerMetrics
private CircuitBreakerMetrics(int slidingWindowSize, CircuitBreakerConfig circuitBreakerConfig, Clock clock)
-
-
Method Details
-
forClosed
-
forHalfOpen
static CircuitBreakerMetrics forHalfOpen(int permittedNumberOfCallsInHalfOpenState, CircuitBreakerConfig circuitBreakerConfig, Clock clock) -
forForcedOpen
-
forDisabled
-
forMetricsOnly
-
onCallNotPermitted
void onCallNotPermitted()Records a call which was not permitted, because the CircuitBreaker state is OPEN. -
onSuccess
Records a successful call and checks if the thresholds are exceeded.- Returns:
- the result of the check
-
onError
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:
getFailureRatein interfaceCircuitBreaker.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:
getSlowCallRatein interfaceCircuitBreaker.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:
getNumberOfSuccessfulCallsin interfaceCircuitBreaker.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:
getNumberOfBufferedCallsin interfaceCircuitBreaker.Metrics- Returns:
- he current total number of buffered calls in the ring buffer
-
getNumberOfFailedCalls
public int getNumberOfFailedCalls()Description copied from interface:CircuitBreaker.MetricsReturns the current number of failed buffered calls in the ring buffer.- Specified by:
getNumberOfFailedCallsin interfaceCircuitBreaker.Metrics- Returns:
- the current number of failed buffered calls in the ring buffer
-
getNumberOfSlowCalls
public int getNumberOfSlowCalls()Description copied from interface:CircuitBreaker.MetricsReturns the current total number of calls which were slower than a certain threshold.- Specified by:
getNumberOfSlowCallsin interfaceCircuitBreaker.Metrics- Returns:
- the current total number of calls which were slower than a certain threshold
-
getNumberOfSlowSuccessfulCalls
public int getNumberOfSlowSuccessfulCalls()Description copied from interface:CircuitBreaker.MetricsReturns the current number of successful calls which were slower than a certain threshold.- Specified by:
getNumberOfSlowSuccessfulCallsin interfaceCircuitBreaker.Metrics- Returns:
- the current number of successful calls which were slower than a certain threshold
-
getNumberOfSlowFailedCalls
public int getNumberOfSlowFailedCalls()Description copied from interface:CircuitBreaker.MetricsReturns the current number of failed calls which were slower than a certain threshold.- Specified by:
getNumberOfSlowFailedCallsin interfaceCircuitBreaker.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:
getNumberOfNotPermittedCallsin interfaceCircuitBreaker.Metrics- Returns:
- the current number of not permitted calls
-