io.micrometer.core.instrument.composite.CompositeMeterRegistry Java Examples
The following examples show how to use
io.micrometer.core.instrument.composite.CompositeMeterRegistry.
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: MoreNamingConventionsTest.java From armeria with Apache License 2.0 | 6 votes |
@Test void configureComposite() { final CompositeMeterRegistry r = new CompositeMeterRegistry(); final NamingConvention oldConvention = (name, type, baseUnit) -> "bar"; r.config().namingConvention(oldConvention); final MeterRegistry pr = newPrometheusRegistry(); final MeterRegistry dr = newDropwizardRegistry(); r.add(pr); r.add(dr); MoreNamingConventions.configure(r); assertThat(r.config().namingConvention()).isSameAs(oldConvention); assertThat(dr.config().namingConvention()).isSameAs(MoreNamingConventions.dropwizard()); assertThat(pr.config().namingConvention()).hasSameClassAs(MoreNamingConventions.prometheus()); }
Example #2
Source File: DropwizardMeterRegistriesTest.java From armeria with Apache License 2.0 | 6 votes |
@Test void filteredGaugesDoNotAffectOthers() { final CompositeMeterRegistry micrometer = new CompositeMeterRegistry(); final PrometheusMeterRegistry prometheus = PrometheusMeterRegistries.newRegistry(); final DropwizardMeterRegistry dropwizard = DropwizardMeterRegistries.newRegistry(); micrometer.add(prometheus).add(dropwizard); final DistributionSummary summary = DistributionSummary.builder("summary") .publishPercentiles(0.5, 0.99) .register(micrometer); summary.record(42); // Make sure Dropwizard registry does not have unwanted gauges. assertThat(dropwizard.getDropwizardRegistry().getMetrics()).containsOnlyKeys("summary"); // Make sure Prometheus registry collects all samples. final MetricFamilySamples prometheusSamples = findPrometheusSample(prometheus, "summary"); assertThat(prometheusSamples.samples).containsExactly( new Sample("summary", ImmutableList.of("quantile"), ImmutableList.of("0.5"), 42), new Sample("summary", ImmutableList.of("quantile"), ImmutableList.of("0.99"), 42), new Sample("summary_count", ImmutableList.of(), ImmutableList.of(), 1), new Sample("summary_sum", ImmutableList.of(), ImmutableList.of(), 42)); }
Example #3
Source File: MoreNamingConventions.java From armeria with Apache License 2.0 | 6 votes |
/** * Configures the specified {@link MeterRegistry} to use the {@link NamingConvention}s provided by this * class. {@link DropwizardMeterRegistry} and {@link PrometheusMeterRegistry} will be configured to use * {@link #dropwizard()} and {@link #prometheus()} respectively. A {@link CompositeMeterRegistry} will be * configured recursively. * * @deprecated Use Micrometer's default {@link NamingConvention}. */ @Deprecated public static void configure(MeterRegistry registry) { requireNonNull(registry, "registry"); if (!Flags.useLegacyMeterNames()) { return; } if (registry instanceof CompositeMeterRegistry) { ((CompositeMeterRegistry) registry).getRegistries().forEach(MoreNamingConventions::configure); } if (registryTypeMatches(registry, "io.micrometer.core.instrument.dropwizard.DropwizardMeterRegistry")) { registry.config().namingConvention(dropwizard()); } else if (registryTypeMatches(registry, "io.micrometer.prometheus.PrometheusMeterRegistry")) { registry.config().namingConvention(prometheus()); } else { // Probably OK to use the default. } }
Example #4
Source File: StatsProviderTest.java From pravega with Apache License 2.0 | 6 votes |
@Test public void testStatsProviderStartWithoutExporting() { MetricsConfig appConfig = MetricsConfig.builder() .with(MetricsConfig.ENABLE_STATSD_REPORTER, true) .with(MetricsConfig.ENABLE_INFLUXDB_REPORTER, true) .build(); CompositeMeterRegistry localRegistry = new CompositeMeterRegistry(); StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry); statsProvider.startWithoutExporting(); for (MeterRegistry registry : localRegistry.getRegistries()) { assertTrue(registry instanceof SimpleMeterRegistry); assertFalse(registry instanceof InfluxMeterRegistry); assertFalse(registry instanceof StatsdMeterRegistry); } statsProvider.close(); assertTrue(0 == localRegistry.getRegistries().size()); }
Example #5
Source File: StatsProviderTest.java From pravega with Apache License 2.0 | 6 votes |
@Test public void testStatsProviderStartAndClose() { //To improve test case isolation, create a new registry instead of using the global one. CompositeMeterRegistry localRegistry = new CompositeMeterRegistry(); MetricsConfig appConfig = MetricsConfig.builder() .with(MetricsConfig.ENABLE_STATSD_REPORTER, true) .with(MetricsConfig.ENABLE_INFLUXDB_REPORTER, false) .build(); StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry); statsProvider.start(); for (MeterRegistry registry : localRegistry.getRegistries()) { assertFalse(registry instanceof InfluxMeterRegistry); assertTrue(registry instanceof StatsdMeterRegistry); } statsProvider.close(); assertTrue(0 == localRegistry.getRegistries().size()); }
Example #6
Source File: MicrometerMetricsExamples.java From vertx-micrometer-metrics with Apache License 2.0 | 6 votes |
public void setupWithCompositeRegistry() { CompositeMeterRegistry myRegistry = new CompositeMeterRegistry(); myRegistry.add(new JmxMeterRegistry(s -> null, Clock.SYSTEM)); myRegistry.add(new GraphiteMeterRegistry(s -> null, Clock.SYSTEM)); Vertx vertx = Vertx.vertx(new VertxOptions() .setMetricsOptions(new MicrometerMetricsOptions() .setMicrometerRegistry(myRegistry) .setEnabled(true))); }
Example #7
Source File: MicrometerAtlasIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void givenCompositeRegistries_whenRecordMeter_thenAllRegistriesRecorded() { CompositeMeterRegistry compositeRegistry = new CompositeMeterRegistry(); SimpleMeterRegistry oneSimpleMeter = new SimpleMeterRegistry(); AtlasMeterRegistry atlasMeterRegistry = new AtlasMeterRegistry(atlasConfig, Clock.SYSTEM); compositeRegistry.add(oneSimpleMeter); compositeRegistry.add(atlasMeterRegistry); compositeRegistry.gauge("baeldung.heat", 90); Optional<Gauge> oneGauge = oneSimpleMeter .find("baeldung.heat") .gauge(); assertTrue(oneGauge.isPresent()); Iterator<Measurement> measurements = oneGauge .get() .measure() .iterator(); assertTrue(measurements.hasNext()); assertThat(measurements .next() .getValue(), equalTo(90.00)); Optional<Gauge> atlasGauge = atlasMeterRegistry .find("baeldung.heat") .gauge(); assertTrue(atlasGauge.isPresent()); Iterator<Measurement> anotherMeasurements = atlasGauge .get() .measure() .iterator(); assertTrue(anotherMeasurements.hasNext()); assertThat(anotherMeasurements .next() .getValue(), equalTo(90.00)); }
Example #8
Source File: StatsProviderTest.java From pravega with Apache License 2.0 | 5 votes |
@Test (expected = Exception.class) public void testStatsProviderNoRegisterBound() { MetricsConfig appConfig = MetricsConfig.builder() .with(MetricsConfig.ENABLE_STATSD_REPORTER, false) .with(MetricsConfig.ENABLE_INFLUXDB_REPORTER, false) .build(); CompositeMeterRegistry localRegistry = new CompositeMeterRegistry(); StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry); statsProvider.start(); }
Example #9
Source File: PrometheusMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void namingConventionOfCustomMeters() { CompositeMeterRegistry composite = new CompositeMeterRegistry(); composite.add(registry); registry.more().counter("my.custom", emptyList(), 0); assertThat(registry.scrape()) .contains("my_custom"); }
Example #10
Source File: MeterMapCleanerTask.java From summerframework with Apache License 2.0 | 5 votes |
public void cleanMeterMap() { log.info("Clean meterMap of {}", this.meterRegistry); if (this.meterRegistry instanceof CompositeMeterRegistry) { CompositeMeterRegistry compositeMeterRegistry = (CompositeMeterRegistry)meterRegistry; this.meterRegistry.getMeters().forEach(this.meterRegistry::remove); compositeMeterRegistry.getRegistries().forEach(meterRegistry1 -> { meterRegistry1.getMeters().forEach(meterRegistry1::remove); }); } else { this.meterRegistry.getMeters().forEach(this.meterRegistry::remove); } }
Example #11
Source File: MossMetricsEndpoint.java From Moss with Apache License 2.0 | 5 votes |
private Collection<Meter> findFirstMatchingMeters(CompositeMeterRegistry composite, String name, Iterable<Tag> tags) { return composite.getRegistries().stream() .map((registry) -> findFirstMatchingMeters(registry, name, tags)) .filter((matching) -> !matching.isEmpty()).findFirst() .orElse(Collections.emptyList()); }
Example #12
Source File: MossMetricsEndpoint.java From Moss with Apache License 2.0 | 5 votes |
private Collection<Meter> findFirstMatchingMeters(MeterRegistry registry, String name, Iterable<Tag> tags) { if (registry instanceof CompositeMeterRegistry) { return findFirstMatchingMeters((CompositeMeterRegistry) registry, name, tags); } return registry.find(name).tags(tags).meters(); }
Example #13
Source File: MossMetricsEndpoint.java From Moss with Apache License 2.0 | 5 votes |
private void collectNames(Set<String> names, MeterRegistry registry) { if (registry instanceof CompositeMeterRegistry) { ((CompositeMeterRegistry) registry).getRegistries() .forEach((member) -> collectNames(names, member)); } else { registry.getMeters().stream().map(this::getName).forEach(names::add); } }
Example #14
Source File: MetricsAutoConfiguration.java From foremast with Apache License 2.0 | 4 votes |
@Bean @Primary public CompositeMeterRegistry compositeMeterRegistry(Clock clock, List<MeterRegistry> registries) { return new CompositeMeterRegistry(clock, registries); }
Example #15
Source File: MetricsAutoConfiguration.java From foremast with Apache License 2.0 | 4 votes |
@Bean public CompositeMeterRegistry noOpMeterRegistry(Clock clock) { return new CompositeMeterRegistry(clock); }
Example #16
Source File: StatsProviderImpl.java From pravega with Apache License 2.0 | 4 votes |
@VisibleForTesting StatsProviderImpl(MetricsConfig conf, CompositeMeterRegistry registry) { this.conf = Preconditions.checkNotNull(conf, "conf"); this.metrics = registry; }
Example #17
Source File: NoOpMeterRegistryConfiguration.java From foremast with Apache License 2.0 | 4 votes |
@Bean public CompositeMeterRegistry noOpMeterRegistry(Clock clock) { return new CompositeMeterRegistry(clock); }
Example #18
Source File: CompositeMeterRegistryConfiguration.java From foremast with Apache License 2.0 | 4 votes |
@Bean @Primary public CompositeMeterRegistry compositeMeterRegistry(Clock clock, List<MeterRegistry> registries) { return new CompositeMeterRegistry(clock, registries); }
Example #19
Source File: MeterRegistryManager.java From jetlinks-community with Apache License 2.0 | 4 votes |
private MeterRegistry createMeterRegistry(String metric, String... tagKeys) { return new CompositeMeterRegistry(Clock.SYSTEM, suppliers.stream() .map(supplier -> supplier.getMeterRegistry(metric, tagKeys)) .collect(Collectors.toList())); }
Example #20
Source File: K8sMetricsAutoConfigurationTest.java From foremast with Apache License 2.0 | 3 votes |
@Test public void customize() { MeterRegistry registry = new CompositeMeterRegistry(); K8sMetricsAutoConfiguration k8sMetricsAutoConfiguration = new K8sMetricsAutoConfiguration(); k8sMetricsAutoConfiguration.metricsProperties = new K8sMetricsProperties(); k8sMetricsAutoConfiguration.customize(registry); }