@Override public void inc(long n) { delegate.inc(n); }
@Override public void inc() { delegate.inc(); }
@Override protected Object prepareAndInvoke(Counter counter, Counted annot, InvocationContext context) throws Exception { counter.inc(); return context.proceed(); }
private void updateMetricsAfter(Throwable throwable, boolean wasBreakerOpen, boolean isClosedNow, boolean breakerWillOpen) { if (!isFaultToleranceMetricsEnabled()) { return; } assert introspector.hasCircuitBreaker(); Method method = introspector.getMethod(); if (throwable == null) { // If no errors increment success counter getCounter(method, BREAKER_CALLS_SUCCEEDED_TOTAL).inc(); } else if (!wasBreakerOpen) { // If error and breaker was closed, increment failed counter getCounter(method, BREAKER_CALLS_FAILED_TOTAL).inc(); // If it will open, increment counter if (breakerWillOpen) { getCounter(method, BREAKER_OPENED_TOTAL).inc(); } } // If breaker was open and still is, increment prevented counter if (wasBreakerOpen && !isClosedNow) { getCounter(method, BREAKER_CALLS_PREVENTED_TOTAL).inc(); } }
/** * Update metrics before method is called. */ private void updateMetricsBefore() { if (isFaultToleranceMetricsEnabled()) { if (introspector.hasRetry() && invocationCount > 1) { getCounter(method, RETRY_RETRIES_TOTAL).inc(); } } }
/** * Updates fallback metrics and adjust failed invocations based on outcome of fallback. */ private void updateMetrics(Throwable throwable) { final Method method = context.getMethod(); FaultToleranceMetrics.getCounter(method, FaultToleranceMetrics.FALLBACK_CALLS_TOTAL).inc(); // If fallback was successful, it is not a failed invocation if (throwable == null) { FaultToleranceMetrics.getCounter(method, FaultToleranceMetrics.INVOCATIONS_FAILED_TOTAL).dec(); } } }
getCounter(method, INVOCATIONS_TOTAL).inc(); getCounter(method, firstInvocation ? RETRY_CALLS_SUCCEEDED_NOT_RETRIED_TOTAL : RETRY_CALLS_SUCCEEDED_RETRIED_TOTAL).inc(); } else if (retry.maxRetries() == invocationCount - 1) { getCounter(method, RETRY_CALLS_FAILED_TOTAL).inc(); getCounter(method, INVOCATIONS_FAILED_TOTAL).inc(); getCounter(method, INVOCATIONS_TOTAL).inc(); getCounter(method, INVOCATIONS_TOTAL).inc(); if (cause != null) { getCounter(method, INVOCATIONS_FAILED_TOTAL).inc(); getCounter(method, cause instanceof TimeoutException ? TIMEOUT_CALLS_TIMED_OUT_TOTAL : TIMEOUT_CALLS_NOT_TIMED_OUT_TOTAL).inc(); : BULKHEAD_CALLS_ACCEPTED_TOTAL).inc();
@Override public void update(Routing.Rules rules) { // register the metric registry and factory to be available to all rules.any((req, res) -> { req.context().register(app); req.context().register(rf); totalCount.inc(); totalMeter.mark(); req.next(); }); rules.anyOf(CollectionsHelper.listOf(Http.Method.GET, Http.Method.OPTIONS), JsonSupport.create()); // routing to root of metrics rules.get(context, (req, res) -> getMultiple(req, res, base, app, vendor)) .options(context, (req, res) -> optionsMultiple(req, res, base, app, vendor)); // routing to each scope Stream.of(app, base, vendor) .forEach(registry -> { String type = registry.type(); rules.get(context + "/" + type, (req, res) -> getAll(req, res, registry)) .get(context + "/" + type + "/{metric}", (req, res) -> getOne(req, res, registry)) .options(context + "/" + type, (req, res) -> optionsAll(req, res, registry)) .options(context + "/" + type + "/{metric}", (req, res) -> optionsOne(req, res, registry)); }); }
public void increment(long n) { counter.inc(n); } }
@Override protected Object prepareAndInvoke(Counter counter, Counted annot, InvocationContext context) throws Exception { counter.inc(); return context.proceed(); }
public void countMe() { Counter counter = metrics.counter("metricTest.test1.count"); counter.inc(); }
private void counterInc(String name) { counterOf(name).inc(); }
private Object invoke(final InvocationContext context, final Executable executable) throws Exception { final Meta counter = findCounter(executable); counter.counter.inc(); try { return context.proceed(); } finally { if (!counter.skipDecrement) { counter.counter.dec(); } } }
@Override public void markNonSuccess() { if (status.compareAndSet(Status.HALF_OPEN, Status.OPEN)) { //This thread wins the race to re-open the circuit - it resets the start time for the sleep window circuitOpened.set(System.currentTimeMillis()); this.successfulInvocations.set(0); this.failedInvocations.set(0); this.remainingHalfOpenInvocations.set(successThreshold); this.metricsCollection.getOpened().inc(); this.markStatusChange(Status.HALF_OPEN); } else { this.failedInvocations.incrementAndGet(); checkThresholds(); } }
private void updateExecutionSuccessfulMetrics(ExecutionMetadata metadata, InvocationContext invocationContext, HystrixCommand cmd) { Optional<TimeoutMetricsCollection> metricsCollection = metadata.getTimeoutMetricsCollection(invocationContext .getMethod().getName()); if (metricsCollection.isPresent()) { metricsCollection.get().getExecutionDuration().update(cmd.getExecutionTimeInMilliseconds() * 1000000); metricsCollection.get().getCallsNotTimedOut().inc(); } metadata.getCbMetricsCollection(invocationContext.getMethod().getName()) .ifPresent(c -> c.getCallsSucceeded().inc()); }
private void markBulkheadRejected(ExecutionMetadata metadata, InvocationContext invocationContext) { metadata.getBulkheadMetricsCollection(invocationContext.getMethod().getName()) .ifPresent(c -> c.getCallsRejected().inc()); if (metadata.isAsynchronous()) { metadata.getBulkheadMetricsCollection(invocationContext.getMethod().getName()) .ifPresent(c -> c.getCurrentlyWaiting().decrementAndGet()); } }
@InSequence(3) public void incrementCountersFromInjection(@Metric(name = "ratioGauge", absolute = true) Gauge<Double> gauge, @Metric(name = "counter1", absolute = true) Counter counter1, @Metric(name = "counter2", absolute = true) Counter counter2) { counter1.inc(Math.round(Math.random() * Integer.MAX_VALUE)); counter2.inc(Math.round(Math.random() * Integer.MAX_VALUE)); assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(((double) counter1.getCount()) / ((double) counter2.getCount())))); assertThat("Gauge is not registered correctly", registry.getGauges(), hasKey("ratioGauge")); @SuppressWarnings("unchecked") Gauge<Double> gaugeFromRegistry = (Gauge<Double>) registry.getGauges().get("ratioGauge"); assertThat("Gauge values from registry and injection do not match", gauge.getValue(), is(equalTo(gaugeFromRegistry.getValue()))); } }
@Test @InSequence(2) public void incrementTest() { count.inc(); Assert.assertEquals(1, count.getCount()); }
@Override public Object execute(InvocationContext invocationContext, RequestContext requestContext, ExecutionMetadata metadata) throws Exception { HystrixCommandConfiguration hystrixCommandConfig = getHystrixCommandSetter(metadata); metadata.getCommonMetricsCollection(invocationContext.getMethod().getName()) .ifPresent(c -> c.getTotalInvocations().inc()); try { if (metadata.getRetry() == null) { return executeWithHystrix(hystrixCommandConfig, invocationContext, requestContext, metadata); } else { return executeWithRetry(hystrixCommandConfig, invocationContext, requestContext, metadata, null, 1, null); } } catch (Exception e) { metadata.getCommonMetricsCollection(invocationContext.getMethod().getName()) .ifPresent(c -> c.getFailedInvocations().inc()); throw e; } }
@Test @InSequence(3) public void incrementLongTest() { count.inc(4); Assert.assertEquals(5, count.getCount()); }