@Override public Map<String, Metric> getMetrics() { return metricRegistry.getMetrics(); } }
@Override public Map<String, Metric> getMetrics() { return metricRegistry.getMetrics(); } }
@Override public Map<String, Metric> getMetrics() { return metricRegistry.getMetrics(); } }
@Override public Map<String, Metric> getMetrics() { return metricRegistry.getMetrics(); } }
@Override public Map<String, Metric> getMetrics() { return metricRegistry.getMetrics(); } }
/** * Returns a map of all the meters in the registry and their names which match the given filter. * * @param filter the metric filter to match * @return all the meters in the registry */ public SortedMap<String, Meter> getMeters(MetricFilter filter) { return getMetrics(Meter.class, filter); }
/** * Returns a map of all the timers in the registry and their names which match the given filter. * * @param filter the metric filter to match * @return all the timers in the registry */ public SortedMap<String, Timer> getTimers(MetricFilter filter) { return getMetrics(Timer.class, filter); }
/** * Returns a map of all the gauges in the registry and their names which match the given filter. * * @param filter the metric filter to match * @return all the gauges in the registry */ @SuppressWarnings("rawtypes") public SortedMap<String, Gauge> getGauges(MetricFilter filter) { return getMetrics(Gauge.class, filter); }
/** * Returns a map of all the counters in the registry and their names which match the given * filter. * * @param filter the metric filter to match * @return all the counters in the registry */ public SortedMap<String, Counter> getCounters(MetricFilter filter) { return getMetrics(Counter.class, filter); }
/** * Returns a map of all the histograms in the registry and their names which match the given * filter. * * @param filter the metric filter to match * @return all the histograms in the registry */ public SortedMap<String, Histogram> getHistograms(MetricFilter filter) { return getMetrics(Histogram.class, filter); }
public static <T extends Metric> T safelyRegister(MetricRegistry metricRegistry, String name, T metric) { try { return metricRegistry.register(name, metric); } catch (IllegalArgumentException ignored) { // safely ignore already existing metric, and simply return the one registered previously. // note that we do not guard against differing metric types here, we consider that a programming error for now. //noinspection unchecked return (T) metricRegistry.getMetrics().get(name); } }
@Override public void close() throws Exception { if (reporters != null) { for (Closeable reporter : reporters) { reporter.close(); } } for (Map.Entry<String, Metric> metric : metricRegistry.getMetrics().entrySet()) { metricRegistry.remove(metric.getKey()); } timers.invalidateAll(); counters.invalidateAll(); meters.invalidateAll(); }
@GET @Timed @Path("/{metricName}") @ApiOperation(value = "Get a single metric") @ApiResponses(value = { @ApiResponse(code = 404, message = "No such metric") }) @Produces(MediaType.APPLICATION_JSON) public Metric singleMetric(@ApiParam(name = "metricName", required = true) @PathParam("metricName") String metricName) { checkPermission(RestPermissions.METRICS_READ, metricName); final Metric metric = metricRegistry.getMetrics().get(metricName); if (metric == null) { final String msg = "I do not have a metric called [" + metricName + "]."; LOG.debug(msg); throw new NotFoundException(msg); } return metric; }
@ReadOperation public Map<String, Object> invoke() { Map<String, Object> result = new HashMap<>(); if (instrumentationManager != null) { result.put("metrics", instrumentationManager.getMetricRegistry().getMetrics()); result.put("runtime", instrumentationManager.getRuntime()); } else { result.put("warning", "please add metrics-core dependency, we use it for metrics"); } return result; }
private void cleanupMetrics() { if (localRegistry != null && localRegistry.getMetrics() != null) for (String metricName : localRegistry.getMetrics().keySet()) metricRegistry.remove(getUniqueReadableId() + "." + metricName); if (this.transportMetrics != null && this.transportMetrics.getMetrics() != null) for (String metricName : this.transportMetrics.getMetrics().keySet()) metricRegistry.remove(getUniqueReadableId() + "." + metricName); }
@POST @Timed @Path("/multiple") @ApiOperation("Get the values of multiple metrics at once") @ApiResponses(value = { @ApiResponse(code = 400, message = "Malformed body") }) @NoAuditEvent("only used to retrieve multiple metrics") public MetricsSummaryResponse multipleMetrics(@ApiParam(name = "Requested metrics", required = true) @Valid @NotNull MetricsReadRequest request) { final Map<String, Metric> metrics = metricRegistry.getMetrics(); final List<Map<String, Object>> metricsList = Lists.newArrayList(); for (String name : request.metrics()) { if (!isPermitted(RestPermissions.METRICS_READ, name)) { continue; } final Metric metric = metrics.get(name); if (metric != null) { metricsList.add(MetricUtils.map(name, metric)); } } return MetricsSummaryResponse.create(metricsList); }
@Test public void shouldUseCustomPrefix() { //Given AsyncRetryRegistry retryRegistry = AsyncRetryRegistry.ofDefaults(); AsyncRetry retry = retryRegistry.retry("testName"); metricRegistry.registerAll(AsyncRetryMetrics.ofAsyncRetryRegistry("testPrefix",retryRegistry)); // Given the HelloWorldService returns Hello world BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn(CompletableFuture.completedFuture("Hello world")); String value = awaitResult(retry.executeCompletionStage(scheduler, helloWorldService::returnHelloWorld)); //Then assertThat(value).isEqualTo("Hello world"); // Then the helloWorldService should be invoked 1 time BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld(); assertThat(metricRegistry.getMetrics()).hasSize(4); assertThat(metricRegistry.getGauges().get("testPrefix.testName." + SUCCESSFUL_CALLS_WITH_RETRY).getValue()).isEqualTo(0L); assertThat(metricRegistry.getGauges().get("testPrefix.testName." + SUCCESSFUL_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(1L); assertThat(metricRegistry.getGauges().get("testPrefix.testName." + FAILED_CALLS_WITH_RETRY).getValue()).isEqualTo(0L); assertThat(metricRegistry.getGauges().get("testPrefix.testName." + FAILED_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(0L); }
@Test public void shouldRegisterMetricsWithoutRetry() throws Throwable { //Given RetryRegistry retryRegistry = RetryRegistry.ofDefaults(); Retry retry = retryRegistry.retry("testName"); metricRegistry.registerAll(RetryMetrics.ofRetryRegistry(retryRegistry)); // Given the HelloWorldService returns Hello world BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world"); // Setup circuitbreaker with retry String value = retry.executeSupplier(helloWorldService::returnHelloWorld); //Then assertThat(value).isEqualTo("Hello world"); // Then the helloWorldService should be invoked 1 time BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld(); assertThat(metricRegistry.getMetrics()).hasSize(4); assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + SUCCESSFUL_CALLS_WITH_RETRY).getValue()).isEqualTo(0L); assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + SUCCESSFUL_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(1L); assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + FAILED_CALLS_WITH_RETRY).getValue()).isEqualTo(0L); assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + FAILED_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(0L); }
@Test public void shouldUseCustomPrefix() throws Throwable { //Given RetryRegistry retryRegistry = RetryRegistry.ofDefaults(); Retry retry = retryRegistry.retry("testName"); metricRegistry.registerAll(RetryMetrics.ofRetryRegistry("testPrefix",retryRegistry)); // Given the HelloWorldService returns Hello world BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world"); String value = retry.executeSupplier(helloWorldService::returnHelloWorld); //Then assertThat(value).isEqualTo("Hello world"); // Then the helloWorldService should be invoked 1 time BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld(); assertThat(metricRegistry.getMetrics()).hasSize(4); assertThat(metricRegistry.getGauges().get("testPrefix.testName." + SUCCESSFUL_CALLS_WITH_RETRY).getValue()).isEqualTo(0L); assertThat(metricRegistry.getGauges().get("testPrefix.testName." + SUCCESSFUL_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(1L); assertThat(metricRegistry.getGauges().get("testPrefix.testName." + FAILED_CALLS_WITH_RETRY).getValue()).isEqualTo(0L); assertThat(metricRegistry.getGauges().get("testPrefix.testName." + FAILED_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(0L); } }
@Test public void shouldRegisterMetrics() throws Throwable { //Given RateLimiterRegistry rateLimiterRegistry = RateLimiterRegistry.ofDefaults(); RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter("testLimit"); metricRegistry.registerAll(RateLimiterMetrics.ofRateLimiterRegistry(rateLimiterRegistry)); // Given the HelloWorldService returns Hello world BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world"); //When String value = rateLimiter.executeSupplier(helloWorldService::returnHelloWorld); //Then assertThat(value).isEqualTo("Hello world"); // Then the helloWorldService should be invoked 1 time BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld(); assertThat(metricRegistry.getMetrics()).hasSize(2); assertThat(metricRegistry.getGauges().get("resilience4j.ratelimiter.testLimit.number_of_waiting_threads") .getValue()).isEqualTo(0); assertThat(metricRegistry.getGauges().get("resilience4j.ratelimiter.testLimit.available_permissions").getValue()) .isIn(DEFAULT_LIMIT_FOR_PERIOD, DEFAULT_LIMIT_FOR_PERIOD - 1); }