/** * Resets the metric registry and removes all the metrics. */ public static void clearAllMetrics() { for (String name : METRIC_REGISTRY.getNames()) { METRIC_REGISTRY.remove(name); } }
@GET @Timed @Path("/names") @ApiOperation(value = "Get all metrics keys/names") @RequiresPermissions(RestPermissions.METRICS_ALLKEYS) @Produces(MediaType.APPLICATION_JSON) public MetricNamesResponse metricNames() { return MetricNamesResponse.create(metricRegistry.getNames()); }
put( "host", "unknown" ); SortedSet<String> names = app.getMetricRegistry().getNames(); for (String name : names) { Timer t = app.getMetricRegistry().timer( name );
public void addHost(final Host host) { logger.debug("Adding tracker for {}", host); HostLatencyTracker old = latencies.putIfAbsent(host, new HostLatencyTracker(scale, (30L * minMeasure) / 100L)); if (old == null && hostMetricsEnabled()) { String metricName = MetricsUtil.hostMetricName("LatencyAwarePolicy.latencies.", host); if (!metrics.getRegistry().getNames().contains(metricName)) { logger.debug("Adding gauge " + metricName); metrics .getRegistry() .register( metricName, new Gauge<Long>() { @Override public Long getValue() { TimestampedAverage latency = latencyTracker.latencyOf(host); return (latency == null) ? -1 : latency.average; } }); } } }
private static void registerCacheMetrics(Map<String, Cache> caches) { Set<String> names = MetricManager.INSTANCE.getRegistry().getNames(); for (Map.Entry<String, Cache> entry : caches.entrySet()) { String key = entry.getKey(); Cache cache = entry.getValue(); String hits = String.format("%s.%s", key, "hits"); String miss = String.format("%s.%s", key, "miss"); String exp = String.format("%s.%s", key, "expire"); String size = String.format("%s.%s", key, "size"); String cap = String.format("%s.%s", key, "capacity"); // Avoid registering multiple times if (names.stream().anyMatch(name -> name.endsWith(hits))) { continue; } MetricsUtil.registerGauge(Cache.class, hits, () -> cache.hits()); MetricsUtil.registerGauge(Cache.class, miss, () -> cache.miss()); MetricsUtil.registerGauge(Cache.class, exp, () -> cache.expire()); MetricsUtil.registerGauge(Cache.class, size, () -> cache.size()); MetricsUtil.registerGauge(Cache.class, cap, () -> cache.capacity()); } } }
@Test public void registersMetricsByPrefixAndName() { metricsManager.registerMetric(LIST_CLASS, ERROR_PREFIX, OUT_OF_BOUNDS, GAUGE); assertThat(registry.getNames()).containsExactly(MetricRegistry.name(LIST_CLASS, ERROR_OUT_OF_BOUNDS)); }
@Test public void registersMetricsByName() { metricsManager.registerMetric(LIST_CLASS, ERROR_OOM, GAUGE); assertThat(registry.getNames()).containsExactly(MetricRegistry.name(LIST_CLASS, ERROR_OOM)); }
@Test public void registersSameMetricNameAcrossClasses() { metricsManager.registerMetric(LIST_CLASS, ERROR_OUT_OF_BOUNDS, GAUGE); metricsManager.registerMetric(LIST_ITERATOR_CLASS, ERROR_OUT_OF_BOUNDS, GAUGE); assertThat(registry.getNames()).containsExactly( MetricRegistry.name(LIST_CLASS, ERROR_OUT_OF_BOUNDS), MetricRegistry.name(LIST_ITERATOR_CLASS, ERROR_OUT_OF_BOUNDS)); }
@Test public void registerOrGetMeterMeterRegistersTheFullyQualifiedClassNameMetric() { metricsManager.registerOrGetMeter(LIST_CLASS, ERROR_OUT_OF_BOUNDS); assertThat(registry.getNames()).containsExactly("java.util.List.error.outofbounds"); }
if (engine instanceof GremlinGroovyScriptEngine && getRegistry().getNames().stream().noneMatch(n -> n.endsWith("long-run-compilation-count"))) { final GremlinGroovyScriptEngine gremlinGroovyScriptEngine = (GremlinGroovyScriptEngine) engine; getRegistry().register(
@Test public void registersMetrics() throws InterruptedException { when(closeableLockService.lock(any(), any())).thenReturn(new LockRefreshToken(BigInteger.ONE, Long.MAX_VALUE)); snapshotTransactionManager.runTaskWithRetry(tx -> 42); MetricRegistry registry = snapshotTransactionManager.metricsManager.getRegistry(); assertThat(registry.getNames()) .contains(SETUP_TASK_METRIC_NAME) .contains(FINISH_TASK_METRIC_NAME); assertThat(registry.getTimers().get(SETUP_TASK_METRIC_NAME).getCount()).isGreaterThanOrEqualTo(1); assertThat(registry.getTimers().get(FINISH_TASK_METRIC_NAME).getCount()).isGreaterThanOrEqualTo(1); }
/** * Returns a set of the names of all the metrics in the registry. * * @return the names of all the metrics */ public SortedSet<String> getNames() { return metrics.getNames(); }
@Test public void defaultTrackerGeneratesTimestampMetrics() { createDefaultTracker(); assertThat(metricsManager.getRegistry().getNames()) .containsExactlyInAnyOrder(buildFullyQualifiedMetricName(IMMUTABLE_TIMESTAMP_NAME), buildFullyQualifiedMetricName(FRESH_TIMESTAMP_NAME), buildFullyQualifiedMetricName(UNREADABLE_TIMESTAMP_NAME)); }
/** * Check whether the metrics reporting has been already set up using metricsReportingSetup. * * @param metrics Metric Registry * @return a boolean representing whether metrics reporting has been already set up. * earlier */ public static boolean isMetricsReportingSetUp(@NonNull MetricRegistry metrics) { return metrics.getNames().contains(mpTrigger); }
@Test public void keyValueServiceMetricsDoNotContainUserAgent() { AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAtlasDbConfig()) .build(); MetricRegistry metrics = new MetricRegistry(); TransactionManagers.builder() .config(atlasDbConfig) .userAgent("test") .globalMetricsRegistry(metrics) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .registrar(environment) .build() .serializable(); assertThat(metrics.getNames().stream() .anyMatch(metricName -> metricName.contains(USER_AGENT_NAME)), is(false)); }
@Override public void stop(MetricsComponent component) { SortedSet<String> names = Collections.unmodifiableSortedSet(metricRegistry.getNames()); names.forEach(metricRegistry::remove); component.timeoutsMeter = null; component.errorsMeter = null; component.activeRequests = null; component.requestTimer = null; reporter.stop(); } };
@Deactivate protected void deactivate() { metricRegistry.getNames().stream().forEach(name -> metricRegistry.remove(name)); HystrixPlugins.reset(); }
@GET @Timed @Path("/names") @ApiOperation(value = "Get all metrics keys/names") @RequiresPermissions(RestPermissions.METRICS_ALLKEYS) @Produces(MediaType.APPLICATION_JSON) public MetricNamesResponse metricNames() { return MetricNamesResponse.create(metricRegistry.getNames()); }
@Override public Collection<String> registeredMetricNames() { // START SNIPPET: registry MetricRegistry metricRegistry = metricsProvider.metricRegistry(); // END SNIPPET: registry return metricRegistry.getNames(); }
private void unregisterMetrics() { try { for (String name : HelixKafkaMirrorMakerMetricsReporter.get().getRegistry().getNames()) { HelixKafkaMirrorMakerMetricsReporter.get().getRegistry().remove(name); } } catch (Exception e) { LOGGER.error("Error unregistering metrics!", e); } }