io.micrometer.core.instrument.Meter Java Examples
The following examples show how to use
io.micrometer.core.instrument.Meter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JvmMetricsTest.java From activemq-artemis with Apache License 2.0 | 7 votes |
private void internalTestMetrics(boolean found, boolean memory, boolean gc, boolean thread, String match) throws Exception { ActiveMQServer server = createServer(false, createDefaultInVMConfig() .setMetricsConfiguration(new MetricsConfiguration() .setPlugin(new SimpleMetricsPlugin().init(null)) .setJvmMemory(memory) .setJvmGc(gc) .setJvmThread(thread))); server.start(); boolean result = false; for (Meter.Id meterId : MetricsPluginTest.getMetrics(server).keySet()) { if (meterId.getName().startsWith(match)) { result = true; break; } } assertEquals(found, result); }
Example #2
Source File: RegistryInspector.java From vertx-micrometer-metrics with Apache License 2.0 | 6 votes |
public static List<Datapoint> listDatapoints(String regName, Predicate<Meter> predicate) { List<Datapoint> result = new ArrayList<>(); MeterRegistry registry = BackendRegistries.getNow(regName); if (registry == null) { throw new NoRegistryException(regName); } registry.forEachMeter(m -> { if (predicate.test(m)) { String id = id(m); m.measure().forEach(measurement -> { result.add(new Datapoint(id + "$" + measurement.getStatistic().name(), measurement.getValue())); }); } }); return result; }
Example #3
Source File: TaggedThreadPoolBulkheadMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldAddMetricsForANewlyCreatedRetry() { ThreadPoolBulkhead newBulkhead = bulkheadRegistry.bulkhead("backendB"); assertThat(taggedBulkheadMetrics.meterIdMap).containsKeys("backendA", "backendB"); assertThat(taggedBulkheadMetrics.meterIdMap.get("backendA")).hasSize(5); assertThat(taggedBulkheadMetrics.meterIdMap.get("backendB")).hasSize(5); List<Meter> meters = meterRegistry.getMeters(); assertThat(meters).hasSize(10); Collection<Gauge> gauges = meterRegistry.get(DEFAULT_MAX_THREAD_POOL_SIZE_METRIC_NAME) .gauges(); Optional<Gauge> successful = findMeterByNamesTag(gauges, newBulkhead.getName()); assertThat(successful).isPresent(); assertThat(successful.get().value()) .isEqualTo(newBulkhead.getMetrics().getMaximumThreadPoolSize()); }
Example #4
Source File: TaggedRateLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldAddMetricsForANewlyCreatedRateLimiter() { RateLimiter newRateLimiter = rateLimiterRegistry.rateLimiter("backendB"); assertThat(taggedRateLimiterMetricsPublisher.meterIdMap) .containsKeys("backendA", "backendB"); assertThat(taggedRateLimiterMetricsPublisher.meterIdMap.get("backendA")).hasSize(2); assertThat(taggedRateLimiterMetricsPublisher.meterIdMap.get("backendB")).hasSize(2); List<Meter> meters = meterRegistry.getMeters(); assertThat(meters).hasSize(4); Collection<Gauge> gauges = meterRegistry.get(DEFAULT_AVAILABLE_PERMISSIONS_METRIC_NAME) .gauges(); Optional<Gauge> successful = findMeterByNamesTag(gauges, newRateLimiter.getName()); assertThat(successful).isPresent(); assertThat(successful.get().value()) .isEqualTo(newRateLimiter.getMetrics().getAvailablePermissions()); }
Example #5
Source File: GraphiteHierarchicalNameMapper.java From micrometer with Apache License 2.0 | 6 votes |
@Override public String toHierarchicalName(Meter.Id id, NamingConvention convention) { StringBuilder hierarchicalName = new StringBuilder(); for (String tagKey : tagsAsPrefix) { String tagValue = id.getTag(tagKey); if (tagValue != null) { hierarchicalName.append(convention.tagValue(tagValue)).append("."); } } hierarchicalName.append(id.getConventionName(convention)); for (Tag tag : id.getTagsAsIterable()) { if (!tagsAsPrefix.contains(tag.getKey())) { hierarchicalName.append('.').append(convention.tagKey(tag.getKey())) .append('.').append(convention.tagValue(tag.getValue())); } } return hierarchicalName.toString(); }
Example #6
Source File: MossMetricsEndpoint.java From Moss with Apache License 2.0 | 6 votes |
public MetricResponse metric(String requiredMetricName, @Nullable List<String> tag) { List<Tag> tags = parseTags(tag); Collection<Meter> meters = findFirstMatchingMeters(this.registry, requiredMetricName, tags); if (meters.isEmpty()) { return null; } Map<Statistic, Double> samples = getSamples(meters); Map<String, Set<String>> availableTags = getAvailableTags(meters); tags.forEach((t) -> availableTags.remove(t.getKey())); Meter.Id meterId = meters.iterator().next().getId(); return new MetricResponse(requiredMetricName, meterId.getDescription(), meterId.getBaseUnit(), asList(samples, Sample::new), asList(availableTags, AvailableTag::new)); }
Example #7
Source File: TaggedBulkheadMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void customMetricNamesGetApplied() { MeterRegistry meterRegistry = new SimpleMeterRegistry(); TaggedBulkheadMetricsPublisher taggedBulkheadMetricsPublisher = new TaggedBulkheadMetricsPublisher( BulkheadMetricNames.custom() .availableConcurrentCallsMetricName("custom_available_calls") .maxAllowedConcurrentCallsMetricName("custom_max_allowed_calls") .build(), meterRegistry); BulkheadRegistry bulkheadRegistry = BulkheadRegistry .of(BulkheadConfig.ofDefaults(), taggedBulkheadMetricsPublisher); bulkhead = bulkheadRegistry.bulkhead("backendA"); Set<String> metricNames = meterRegistry.getMeters() .stream() .map(Meter::getId) .map(Meter.Id::getName) .collect(Collectors.toSet()); assertThat(metricNames).hasSameElementsAs(Arrays.asList( "custom_available_calls", "custom_max_allowed_calls" )); }
Example #8
Source File: AbstractBulkheadMetrics.java From resilience4j with Apache License 2.0 | 6 votes |
private void registerMetrics( MeterRegistry meterRegistry, Bulkhead bulkhead, List<Tag> customTags) { // Remove previous meters before register removeMetrics(meterRegistry, bulkhead.getName()); Set<Meter.Id> idSet = new HashSet<>(); idSet.add(Gauge.builder(names.getAvailableConcurrentCallsMetricName(), bulkhead, bh -> bh.getMetrics().getAvailableConcurrentCalls()) .description("The number of available permissions") .tag(TagNames.NAME, bulkhead.getName()) .tags(customTags) .register(meterRegistry).getId()); idSet.add(Gauge.builder(names.getMaxAllowedConcurrentCallsMetricName(), bulkhead, bh -> bh.getMetrics().getMaxAllowedConcurrentCalls()) .description("The maximum number of available permissions") .tag(TagNames.NAME, bulkhead.getName()) .tags(customTags) .register(meterRegistry).getId()); meterIdMap.put(bulkhead.getName(), idSet); }
Example #9
Source File: DefaultDestinationPublishingMeterRegistry.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
protected void publish() { List<Metric<Number>> aggregatedMeters = new ArrayList<>(); for (Meter meter : this.getMeters()) { if (meter instanceof Timer) { aggregatedMeters.add(toTimerMetric((Timer) meter)); } else if (meter instanceof DistributionSummary) { aggregatedMeters.add(toSummaryMetric((DistributionSummary) meter)); } } if (!aggregatedMeters.isEmpty()) { ApplicationMetrics metrics = new ApplicationMetrics( this.applicationProperties.getKey(), aggregatedMeters); metrics.setInterval(this.metricsPublisherConfig.step().toMillis()); metrics.setProperties(this.applicationProperties.getExportProperties()); try { String jsonString = this.objectMapper.writeValueAsString(metrics); this.metricsConsumer.accept(jsonString); } catch (JsonProcessingException e) { logger.warn("Error producing JSON String representation metric data", e); } } }
Example #10
Source File: TaggedBulkheadMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void customMetricNamesGetApplied() { MeterRegistry meterRegistry = new SimpleMeterRegistry(); BulkheadRegistry bulkheadRegistry = BulkheadRegistry.ofDefaults(); bulkhead = bulkheadRegistry.bulkhead("backendA"); TaggedBulkheadMetrics.ofBulkheadRegistry( BulkheadMetricNames.custom() .availableConcurrentCallsMetricName("custom_available_calls") .maxAllowedConcurrentCallsMetricName("custom_max_allowed_calls") .build(), bulkheadRegistry ).bindTo(meterRegistry); Set<String> metricNames = meterRegistry.getMeters() .stream() .map(Meter::getId) .map(Meter.Id::getName) .collect(Collectors.toSet()); assertThat(metricNames).hasSameElementsAs(Arrays.asList( "custom_available_calls", "custom_max_allowed_calls" )); }
Example #11
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 6 votes |
@Test public void disableMetric() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); k8sMetricsProperties.setCommonMetricsWhitelist("prefix_abc"); k8sMetricsProperties.setEnableCommonMetricsFilterAction(true); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); //Whitelist filter.disableMetric("prefix_abc"); reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.DENY); }
Example #12
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 6 votes |
@Test public void disableAction() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); k8sMetricsProperties.setCommonMetricsWhitelist("prefix_abc"); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); //Whitelist filter.disableMetric("prefix_abc"); reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); }
Example #13
Source File: TaggedRetryMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void metricsAreRegisteredWithCustomNames() { MeterRegistry meterRegistry = new SimpleMeterRegistry(); TaggedRetryMetricsPublisher taggedRetryMetricsPublisher = new TaggedRetryMetricsPublisher( RetryMetricNames.custom() .callsMetricName("custom_calls") .build(), meterRegistry); RetryRegistry retryRegistry = RetryRegistry .of(RetryConfig.ofDefaults(), taggedRetryMetricsPublisher); retryRegistry.retry("backendA"); Set<String> metricNames = meterRegistry.getMeters() .stream() .map(Meter::getId) .map(Meter.Id::getName) .collect(Collectors.toSet()); assertThat(metricNames).hasSameElementsAs(Collections.singletonList("custom_calls")); }
Example #14
Source File: TaggedTimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void customMetricNamesGetApplied() { MeterRegistry meterRegistry = new SimpleMeterRegistry(); TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); timeLimiterRegistry.timeLimiter("backendA"); TaggedTimeLimiterMetrics.ofTimeLimiterRegistry( TimeLimiterMetricNames.custom() .callsMetricName("custom_calls") .build(), timeLimiterRegistry ).bindTo(meterRegistry); Set<String> metricNames = meterRegistry.getMeters() .stream() .map(Meter::getId) .map(Meter.Id::getName) .collect(Collectors.toSet()); assertThat(metricNames).hasSameElementsAs(Arrays.asList( "custom_calls" )); }
Example #15
Source File: PropertiesMeterFilter.java From foremast with Apache License 2.0 | 6 votes |
@Override public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) { Distribution distribution = this.properties.getDistribution(); return DistributionStatisticConfig.builder() .percentilesHistogram( lookupWithFallbackToAll(distribution.getPercentilesHistogram(), id, null)) .percentiles( lookupWithFallbackToAll(distribution.getPercentiles(), id, null)) .sla(convertSla(id.getType(), lookup(distribution.getSla(), id, null))) .minimumExpectedValue(convertMeterValue(id.getType(), lookup(distribution.getMinimumExpectedValue(), id, null))) .maximumExpectedValue(convertMeterValue(id.getType(), lookup(distribution.getMaximumExpectedValue(), id, null))) .build().merge(config); }
Example #16
Source File: MeterBuilderTest.java From skywalking with Apache License 2.0 | 6 votes |
@Test public void testConvertId() { final List<MeterId.Tag> meterTags = Arrays.asList(new MeterId.Tag("k1", "v1")); // Counter type check final Meter.Id counterId = new Meter.Id("test", Tags.of("k1", "v1"), null, "test", Meter.Type.COUNTER); assertId(MeterBuilder.convertId(counterId, "test"), "test", MeterId.MeterType.COUNTER, meterTags); // Gauge type check final Meter.Id gaugeId = new Meter.Id("test", Tags.of("k1", "v1"), null, "test", Meter.Type.GAUGE); assertId(MeterBuilder.convertId(gaugeId, "test"), "test", MeterId.MeterType.GAUGE, meterTags); // Histogram type check final Meter.Id otherId = new Meter.Id("test", Tags.of("k1", "v1"), null, "test", Meter.Type.DISTRIBUTION_SUMMARY); assertId(MeterBuilder.convertId(otherId, "test"), "test", MeterId.MeterType.HISTOGRAM, meterTags); }
Example #17
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 6 votes |
@Test public void acceptEnabled() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); filter.setPrefixes(new String[]{"prefix"}); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.ACCEPT); filter.setPrefixes(new String[]{"prefix"}); reply = filter.accept(new Meter.Id("abc_.omething", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.DENY); }
Example #18
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 5 votes |
@Test public void defaultMetricsProperties() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); MetricsProperties metricsProperties = new MetricsProperties(); metricsProperties.getEnable().put("prefix.abc", false); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.DENY); //Disabled }
Example #19
Source File: StepFunctionTimerTest.java From micrometer with Apache License 2.0 | 5 votes |
@SuppressWarnings("ConstantConditions") @Issue("#1814") @Test void meanShouldWorkIfTotalNotCalled() { Queue<Long> counts = new LinkedList<>(); counts.add(2L); counts.add(5L); counts.add(10L); Queue<Double> totalTimes = new LinkedList<>(); totalTimes.add(150.0); totalTimes.add(300.0); totalTimes.add(1000.0); Duration stepDuration = Duration.ofMillis(10); MockClock clock = new MockClock(); StepFunctionTimer<Object> ft = new StepFunctionTimer<>( mock(Meter.Id.class), clock, stepDuration.toMillis(), new Object(), (o) -> counts.poll(), (o) -> totalTimes.poll(), TimeUnit.SECONDS, TimeUnit.SECONDS ); assertThat(ft.count()).isEqualTo(0.0); clock.add(stepDuration); assertThat(ft.mean(TimeUnit.SECONDS)).isEqualTo(300.0 / 5L); clock.add(stepDuration); assertThat(ft.mean(TimeUnit.SECONDS)).isEqualTo(700.0 / 5L); }
Example #20
Source File: TaggedThreadPoolBulkheadMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldAddCustomTags() { bulkheadRegistry.bulkhead("backendF", io.vavr.collection.HashMap.of("key1", "value1")); assertThat(taggedBulkheadMetrics.meterIdMap).containsKeys("backendA", "backendF"); assertThat(taggedBulkheadMetrics.meterIdMap.get("backendA")).hasSize(5); assertThat(taggedBulkheadMetrics.meterIdMap.get("backendF")).hasSize(5); List<Meter> meters = meterRegistry.getMeters(); assertThat(meters).hasSize(10); assertThat(meterRegistry.get(DEFAULT_MAX_THREAD_POOL_SIZE_METRIC_NAME).tag("key1", "value1")).isNotNull(); }
Example #21
Source File: CommonMetricsFilterTest.java From foremast with Apache License 2.0 | 5 votes |
@Test public void acceptWhiteList() { K8sMetricsProperties k8sMetricsProperties = new K8sMetricsProperties(); k8sMetricsProperties.setEnableCommonMetricsFilter(true); k8sMetricsProperties.setCommonMetricsWhitelist("prefix_abc"); MetricsProperties metricsProperties = new MetricsProperties(); CommonMetricsFilter filter = new CommonMetricsFilter(k8sMetricsProperties, metricsProperties); MeterFilterReply reply = filter.accept(new Meter.Id("prefix.abc", null, "", "", Meter.Type.COUNTER)); assertEquals(reply, MeterFilterReply.NEUTRAL); //Whitelist }
Example #22
Source File: MicrometerChannelMetricsRecorder.java From reactor-netty with Apache License 2.0 | 5 votes |
@Nullable protected static <M extends Meter> M filter(M meter) { if (meter instanceof NoopMeter) { return null; } else { return meter; } }
Example #23
Source File: OnlyOnceLoggingDenyMeterFilter.java From foremast with Apache License 2.0 | 5 votes |
@Override public MeterFilterReply accept(Meter.Id id) { if (logger.isWarnEnabled() && this.alreadyWarned.compareAndSet(false, true)) { logger.warn(this.message.get()); } return MeterFilterReply.DENY; }
Example #24
Source File: WavefrontMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void publishDistribution() throws IOException { Meter.Id id = registry.summary("name").getId(); long time = System.currentTimeMillis(); List<Pair<Double, Integer>> centroids = Arrays.asList(new Pair<>(1d, 1)); List<WavefrontHistogramImpl.Distribution> distributions = Arrays.asList( new WavefrontHistogramImpl.Distribution(time, centroids) ); registry.publishDistribution(id, distributions); verify(wavefrontSender, times(1)).sendDistribution("name", centroids, Collections.singleton(HistogramGranularity.MINUTE), time, "host", Collections.emptyMap()); verifyNoMoreInteractions(wavefrontSender); }
Example #25
Source File: TaggedThreadPoolBulkheadMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldRemovedMetricsForRemovedRetry() { List<Meter> meters = meterRegistry.getMeters(); assertThat(meters).hasSize(5); assertThat(taggedBulkheadMetrics.meterIdMap).containsKeys("backendA"); bulkheadRegistry.remove("backendA"); assertThat(taggedBulkheadMetrics.meterIdMap).isEmpty(); meters = meterRegistry.getMeters(); assertThat(meters).isEmpty(); }
Example #26
Source File: AppOpticsMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void writeMeterWhenCustomMeterHasOnlyNonFiniteValuesShouldNotBeWritten() { Measurement measurement1 = new Measurement(() -> Double.POSITIVE_INFINITY, Statistic.VALUE); Measurement measurement2 = new Measurement(() -> Double.NEGATIVE_INFINITY, Statistic.VALUE); Measurement measurement3 = new Measurement(() -> Double.NaN, Statistic.VALUE); List<Measurement> measurements = Arrays.asList(measurement1, measurement2, measurement3); Meter meter = Meter.builder("my.meter", Meter.Type.GAUGE, measurements).register(this.meterRegistry); assertThat(meterRegistry.writeMeter(meter)).isNotPresent(); }
Example #27
Source File: CommonMetricsFilter.java From foremast with Apache License 2.0 | 5 votes |
private <T> T doLookup(Map<String, T> values, Meter.Id id, Supplier<T> defaultValue) { String name = id.getName(); while (name != null && !name.isEmpty()) { T result = values.get(name); if (result != null) { return result; } int lastDot = name.lastIndexOf('.'); name = (lastDot != -1) ? name.substring(0, lastDot) : ""; } return defaultValue.get(); }
Example #28
Source File: RegistryInspector.java From vertx-micrometer-metrics with Apache License 2.0 | 5 votes |
private static String id(Meter m) { return m.getId().getName() + "[" + StreamSupport.stream(m.getId().getTags().spliterator(), false) .map(t -> t.getKey() + '=' + t.getValue()) .collect(Collectors.joining(",")) + "]"; }
Example #29
Source File: SkywalkingMeterRegistry.java From skywalking with Apache License 2.0 | 5 votes |
@Override protected <T> FunctionCounter newFunctionCounter(Meter.Id id, T obj, ToDoubleFunction<T> countFunction) { final MeterId meterId = convertId(id); FunctionCounter fc = new CumulativeFunctionCounter<>(id, obj, countFunction); new SkywalkingCustomCounter.Builder(meterId, new Measurement(() -> countFunction.applyAsDouble(obj), Statistic.COUNT), config).build(); return fc; }
Example #30
Source File: BackendRegistries.java From vertx-micrometer-metrics with Apache License 2.0 | 5 votes |
private static MeterFilter replaceTagValues(MetricsDomain domain, String tagKey, Function<String, String> replacement) { return new MeterFilter() { @Override public Meter.Id map(Meter.Id id) { if (domain != null && !id.getName().startsWith(domain.getPrefix())) { return id; } return MeterFilter.replaceTagValues(tagKey, replacement).map(id); } }; }