@Override public Integer getValue() { return metrics.getHealthCounts().getErrorPercentage(); } });
@Override public boolean isOpen() { System.out.println("metrics : " + metrics.getCommandKey().name() + " : " + metrics.getHealthCounts()); if (forceShortCircuit) { return true; } else { return metrics.getHealthCounts().getErrorCount() >= 3; } }
private <T> void logHC(HystrixInvokable<T> command, T response) { if(command instanceof HystrixInvokableInfo) { HystrixInvokableInfo<T> commandInfo = (HystrixInvokableInfo<T>)command; HystrixCommandMetrics metrics = commandInfo.getMetrics(); System.out.println("cb/error-count/%/total: " + commandInfo.isCircuitBreakerOpen() + " " + metrics.getHealthCounts().getErrorCount() + " " + metrics.getHealthCounts().getErrorPercentage() + " " + metrics.getHealthCounts().getTotalRequests() + " => " + response + " " + commandInfo.getExecutionEvents()); } } }
cmd1.execute(); Thread.sleep(100); assertEquals(0, metrics.getHealthCounts().getErrorPercentage()); assertEquals(50, metrics.getHealthCounts().getErrorPercentage()); assertEquals(50, metrics.getHealthCounts().getErrorPercentage()); cmd6.execute(); Thread.sleep(100); assertEquals(75, metrics.getHealthCounts().getErrorPercentage()); } catch (Exception e) { e.printStackTrace();
cmd1.execute(); Thread.sleep(100); assertEquals(0, metrics.getHealthCounts().getErrorPercentage()); assertEquals(50, metrics.getHealthCounts().getErrorPercentage()); cmd4.execute(); Thread.sleep(100); assertEquals(25, metrics.getHealthCounts().getErrorPercentage()); cmd6.execute(); Thread.sleep(100); assertEquals(50, metrics.getHealthCounts().getErrorPercentage()); assertEquals(30, metrics.getHealthCounts().getErrorPercentage());
System.out.println("CircuitBreaker state 1 : " + cmd1.getMetrics().getHealthCounts()); assertTrue(cb.isOpen()); System.out.println("CircuitBreaker state 2 : " + cmd1.getMetrics().getHealthCounts()); assertTrue(cb.allowRequest()); assertTrue(cb.allowRequest());
System.out.println("Current CircuitBreaker Status : " + cmd1.getMetrics().getHealthCounts()); assertTrue(cb.allowRequest()); assertFalse(cb.isOpen());
public CircutBreakerEvent(HystrixCommandKey commandKey, Type type) { super(type); HystrixCommandMetrics hystrixCommandMetrics = HystrixCommandMetrics.getInstance(commandKey); if (hystrixCommandMetrics != null) { if (hystrixCommandMetrics.getCommandGroup() instanceof CustomizeCommandGroupKey) { CustomizeCommandGroupKey customCommandGroupKey = (CustomizeCommandGroupKey) hystrixCommandMetrics.getCommandGroup(); this.microservice = customCommandGroupKey.getInstance().getMicroserviceName(); this.role = customCommandGroupKey.getInstance().getInvocationType().name(); this.schema = customCommandGroupKey.getInstance().getSchemaId(); this.operation = customCommandGroupKey.getInstance().getOperationName(); } this.currentTotalRequest = hystrixCommandMetrics.getHealthCounts().getTotalRequests(); this.currentErrorPercentage = hystrixCommandMetrics.getHealthCounts().getErrorCount(); this.currentErrorCount = hystrixCommandMetrics.getHealthCounts().getErrorPercentage(); this.requestVolumeThreshold = hystrixCommandMetrics.getProperties().circuitBreakerRequestVolumeThreshold().get(); this.sleepWindowInMilliseconds = hystrixCommandMetrics.getProperties().circuitBreakerSleepWindowInMilliseconds().get(); this.errorThresholdPercentage = hystrixCommandMetrics.getProperties().circuitBreakerErrorThresholdPercentage().get(); } }
@Override public void initialize() { logger.info("JboneHystrixMetricsPublisherCommand initialize start"); logger.info("commandKey: {}",commandKey); logger.info("commandGroupKey: {}",commandGroupKey); logger.info("metrics: {}",metrics.getHealthCounts()); logger.info("circuitBreaker: {}",circuitBreaker.isOpen()); logger.info("properties: {}",properties); logger.info("JboneHystrixMetricsPublisherCommand initialize end."); } }
@Override public Integer getValue() { return metrics.getHealthCounts().getErrorPercentage(); } });
@Override public Integer call() { return metrics.getHealthCounts().getErrorPercentage(); } };
@Override public Integer call() { return metrics.getHealthCounts().getErrorPercentage(); } };
private 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.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(); }
private 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.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(); }
private void printMetrics() { HystrixCommandMetrics metrics = HystrixCommandMetrics. getInstance(HystrixCommandKey.Factory.asKey(this.getClass().getSimpleName())); StringBuilder m = new StringBuilder(); if (metrics != null) { HystrixCommandMetrics.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.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(" "); } System.out.println(m); } }
@Override public boolean isOpen() { if (circuitOpen.get()) { // if we're open we immediately return true and don't bother attempting to 'close' ourself as that is left to allowSingleTest and a subsequent successful test to close return true; } // we're closed, so let's see if errors have made us so we should trip the circuit open HealthCounts health = metrics.getHealthCounts(); // check if we are past the statisticalWindowVolumeThreshold if (health.getTotalRequests() < properties.circuitBreakerRequestVolumeThreshold().get()) { // we are not past the minimum volume threshold for the statisticalWindow so we'll return false immediately and not calculate anything return false; } if (health.getErrorPercentage() < properties.circuitBreakerErrorThresholdPercentage().get()) { return false; } else { // our failure rate is too high, trip the circuit if (circuitOpen.compareAndSet(false, true)) { // if the previousValue was false then we want to set the currentTime circuitOpenedOrLastTestedTime.set(System.currentTimeMillis()); return true; } else { // How could previousValue be true? If another thread was going through this code at the same time a race-condition could have // caused another thread to set it to true already even though we were in the process of doing the same // In this case, we know the circuit is open, so let the other thread set the currentTime and report back that the circuit is open return true; } } }
json.writeBooleanField("isCircuitBreakerOpen", circuitBreaker.isOpen()); HealthCounts healthCounts = commandMetrics.getHealthCounts(); json.writeNumberField("errorPercentage", healthCounts.getErrorPercentage()); json.writeNumberField("errorCount", healthCounts.getErrorCount());
json.writeBooleanField("isCircuitBreakerOpen", circuitBreaker.isOpen()); HystrixCommandMetrics.HealthCounts healthCounts = commandMetrics.getHealthCounts(); json.writeNumberField("errorPercentage", healthCounts.getErrorPercentage()); json.writeNumberField("errorCount", healthCounts.getErrorCount());
public CircutBreakerEvent(HystrixCommandKey commandKey, Type type) { super(type); HystrixCommandMetrics hystrixCommandMetrics = HystrixCommandMetrics.getInstance(commandKey); if (hystrixCommandMetrics != null) { if (hystrixCommandMetrics.getCommandGroup() instanceof CustomizeCommandGroupKey) { CustomizeCommandGroupKey customCommandGroupKey = (CustomizeCommandGroupKey) hystrixCommandMetrics.getCommandGroup(); this.microservice = customCommandGroupKey.getInstance().getMicroserviceName(); this.role = customCommandGroupKey.getInstance().getInvocationType().name(); this.schema = customCommandGroupKey.getInstance().getSchemaId(); this.operation = customCommandGroupKey.getInstance().getOperationName(); } this.currentTotalRequest = hystrixCommandMetrics.getHealthCounts().getTotalRequests(); this.currentErrorPercentage = hystrixCommandMetrics.getHealthCounts().getErrorCount(); this.currentErrorCount = hystrixCommandMetrics.getHealthCounts().getErrorPercentage(); this.requestVolumeThreshold = hystrixCommandMetrics.getProperties().circuitBreakerRequestVolumeThreshold().get(); this.sleepWindowInMilliseconds = hystrixCommandMetrics.getProperties().circuitBreakerSleepWindowInMilliseconds().get(); this.errorThresholdPercentage = hystrixCommandMetrics.getProperties().circuitBreakerErrorThresholdPercentage().get(); } }
json.writeBooleanField("isCircuitBreakerOpen", circuitBreaker.isOpen()); HystrixCommandMetrics.HealthCounts healthCounts = commandMetrics.getHealthCounts(); json.writeNumberField("errorPercentage", healthCounts.getErrorPercentage()); json.writeNumberField("errorCount", healthCounts.getErrorCount());