io.micrometer.core.instrument.simple.SimpleMeterRegistry Java Examples
The following examples show how to use
io.micrometer.core.instrument.simple.SimpleMeterRegistry.
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: TimerTest.java From micrometer with Apache License 2.0 | 8 votes |
@DisplayName("autocloseable sample") @ParameterizedTest(name = "when outcome is '{0}'") @CsvSource({"success", "error"}) @Issue("#1425") default void closeable(String outcome) { MeterRegistry registry = new SimpleMeterRegistry(); try (Timer.ResourceSample sample = Timer.resource(registry, "requests") .description("This is an operation") .publishPercentileHistogram()) { try { if (outcome.equals("error")) { throw new IllegalArgumentException("boom"); } sample.tag("outcome", "success"); } catch (Throwable t) { sample.tag("outcome", "error"); } } assertThat(registry.get("requests").tag("outcome", outcome).timer().count()) .isEqualTo(1); }
Example #2
Source File: TimersTest.java From vertx-micrometer-metrics with Apache License 2.0 | 6 votes |
@Test public void shouldAliasTimerLabel() { MeterRegistry registry = new SimpleMeterRegistry(); BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match() .setLabel("address") .setType(MatchType.REGEX) .setValue("addr1") .setAlias("1"))); Timers timers = new Timers("my_timer", "", registry, Label.EB_ADDRESS); timers.get("addr1").record(5, TimeUnit.MILLISECONDS); timers.get("addr1").record(8, TimeUnit.MILLISECONDS); timers.get("addr2").record(10, TimeUnit.MILLISECONDS); Timer t = registry.find("my_timer").tags("address", "1").timer(); assertThat(t.count()).isEqualTo(2); assertThat(t.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(13); t = registry.find("my_timer").tags("address", "addr1").timer(); assertThat(t).isNull(); t = registry.find("my_timer").tags("address", "addr2").timer(); assertThat(t.count()).isEqualTo(1); assertThat(t.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(10); }
Example #3
Source File: RecordFileParserTest.java From hedera-mirror-node with Apache License 2.0 | 6 votes |
@BeforeEach void before() { var mirrorProperties = new MirrorProperties(); mirrorProperties.setDataPath(dataPath); parserProperties = new RecordParserProperties(mirrorProperties); parserProperties.setKeepFiles(false); parserProperties.init(); recordFileParser = new RecordFileParser(applicationStatusRepository, parserProperties, new SimpleMeterRegistry(), recordItemListener, recordStreamFileListener); StreamType streamType = StreamType.RECORD; fileCopier = FileCopier .create(Path.of(this.getClass().getClassLoader().getResource("data").getPath()), dataPath) .from(streamType.getPath(), "v2", "record0.0.3") .filterFiles("*.rcd") .to(streamType.getPath(), streamType.getValid()); file1 = parserProperties.getValidPath().resolve("2019-08-30T18_10_00.419072Z.rcd").toFile(); file2 = parserProperties.getValidPath().resolve("2019-08-30T18_10_05.249678Z.rcd").toFile(); recordFile1 = new RecordFile(1567188600419072000L, 1567188604906443001L, null, file1.getPath(), 0L, 0L, "591558e059bd1629ee386c4e35a6875b4c67a096718f5d225772a651042715189414df7db5588495efb2a85dc4a0ffda", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 2); recordFile2 = new RecordFile(1567188605249678000L, 1567188609705382001L, null, file2.getPath(), 0L, 0L, "5ed51baeff204eb6a2a68b76bbaadcb9b6e7074676c1746b99681d075bef009e8d57699baaa6342feec4e83726582d36", recordFile1.getFileHash(), 2); }
Example #4
Source File: MetricsRequestEventListenerTimedTest.java From micrometer with Apache License 2.0 | 6 votes |
@Override protected Application configure() { registry = new SimpleMeterRegistry(); longTaskRequestStartedLatch = new CountDownLatch(1); longTaskRequestReleaseLatch = new CountDownLatch(1); final MetricsApplicationEventListener listener = new MetricsApplicationEventListener( registry, new DefaultJerseyTagsProvider(), METRIC_NAME, false); final ResourceConfig config = new ResourceConfig(); config.register(listener); config.register( new TimedResource(longTaskRequestStartedLatch, longTaskRequestReleaseLatch)); config.register(TimedOnClassResource.class); return config; }
Example #5
Source File: HistogramGaugesTest.java From micrometer with Apache License 2.0 | 6 votes |
@Test void histogramsContainLongMaxValue() { MeterRegistry registry = new SimpleMeterRegistry(); Timer timer = Timer.builder("my.timer") .serviceLevelObjectives(Duration.ofNanos(Long.MAX_VALUE)) .register(registry); DistributionSummary distributionSummary = DistributionSummary.builder("my.distribution") .serviceLevelObjectives(Double.POSITIVE_INFINITY) .register(registry); HistogramGauges distributionGauges = HistogramGauges.registerWithCommonFormat(distributionSummary, registry); HistogramGauges timerGauges = HistogramGauges.registerWithCommonFormat(timer, registry); assertThat(registry.get("my.distribution.histogram").tag("le", "+Inf").gauge()).isNotNull(); assertThat(registry.get("my.timer.histogram").tag("le", "+Inf").gauge()).isNotNull(); }
Example #6
Source File: CommonsObjectPool2MetricsTest.java From micrometer with Apache License 2.0 | 6 votes |
@Test void verifyMetricsWithExpectedTags() { createGenericObjectPool(); MeterRegistry registry = new SimpleMeterRegistry(); commonsObjectPool2Metrics.bindTo(registry); registry.get("commons.pool2.num.idle").tags(tags).gauge(); registry.get("commons.pool2.num.waiters").tags(tags).gauge(); Arrays.asList( "commons.pool2.created", "commons.pool2.borrowed", "commons.pool2.returned", "commons.pool2.destroyed", "commons.pool2.destroyed.by.evictor", "commons.pool2.destroyed.by.borrow.validation" ).forEach(name -> registry.get(name).tags(tags).functionCounter()); Arrays.asList( "commons.pool2.max.borrow.wait", "commons.pool2.mean.active", "commons.pool2.mean.idle", "commons.pool2.mean.borrow.wait" ).forEach(name -> registry.get(name).tags(tags).timeGauge()); }
Example #7
Source File: RegressionMetricsTest.java From konduit-serving with Apache License 2.0 | 6 votes |
@Test public void testRegressionValue() { RegressionMetricsConfig regressionMetricsConfig = RegressionMetricsConfig.builder() .regressionColumnLabels(Arrays.asList("test")) .sampleTypes(Arrays.asList(RegressionMetricsConfig.SampleType.MEAN)) .columnDistributions(Arrays.asList(ColumnDistribution.builder() .max(1.0).min(0.0).normalizerType(NormalizerType.MIN_MAX).build())) .build(); RegressionMetrics regressionMetrics = new RegressionMetrics(regressionMetricsConfig); regressionMetrics.bindTo(new SimpleMeterRegistry()); regressionMetrics.updateMetrics(new INDArray[] {Nd4j.scalar(1.0).reshape(1,1)}); Gauge gauge = regressionMetrics.getOutputStatsGauges().get(0); double value = gauge.value(); assertEquals(1.0,value,1e-1); }
Example #8
Source File: KafkaMetricsTest.java From micrometer with Apache License 2.0 | 6 votes |
@Issue("#1968") @Test void shouldRemoveOlderMeterWithLessTagsWhenCommonTagsConfigured() { //Given Map<String, String> tags = new LinkedHashMap<>(); Supplier<Map<MetricName, ? extends Metric>> supplier = () -> { MetricName metricName = new MetricName("a", "b", "c", tags); KafkaMetric metric = new KafkaMetric(this, metricName, new Value(), new MetricConfig(), Time.SYSTEM); return Collections.singletonMap(metricName, metric); }; kafkaMetrics = new KafkaMetrics(supplier); MeterRegistry registry = new SimpleMeterRegistry(); registry.config().commonTags("common", "value"); kafkaMetrics.bindTo(registry); assertThat(registry.getMeters()).hasSize(1); assertThat(registry.getMeters().get(0).getId().getTags()).containsExactlyInAnyOrder(Tag.of("kafka-version", "unknown"), Tag.of("common", "value")); // only version tags.put("key0", "value0"); kafkaMetrics.checkAndBindMetrics(registry); assertThat(registry.getMeters()).hasSize(1); assertThat(registry.getMeters().get(0).getId().getTags()).containsExactlyInAnyOrder(Tag.of("kafka-version", "unknown"), Tag.of("key0", "value0"), Tag.of("common", "value")); }
Example #9
Source File: KafkaMetricsTest.java From micrometer with Apache License 2.0 | 6 votes |
@Test void shouldBindMetersWithSameTags() { Supplier<Map<MetricName, ? extends Metric>> supplier = () -> { Map<String, String> firstTags = new LinkedHashMap<>(); firstTags.put("key0", "value0"); MetricName firstName = new MetricName("a", "b", "c", firstTags); KafkaMetric firstMetric = new KafkaMetric(this, firstName, new Value(), new MetricConfig(), Time.SYSTEM); Map<String, String> secondTags = new LinkedHashMap<>(); secondTags.put("key0", "value1"); MetricName secondName = new MetricName("a", "b", "c", secondTags); KafkaMetric secondMetric = new KafkaMetric(this, secondName, new Value(), new MetricConfig(), Time.SYSTEM); Map<MetricName, KafkaMetric> metrics = new LinkedHashMap<>(); metrics.put(firstName, firstMetric); metrics.put(secondName, secondMetric); return metrics; }; kafkaMetrics = new KafkaMetrics(supplier); MeterRegistry registry = new SimpleMeterRegistry(); kafkaMetrics.bindTo(registry); assertThat(registry.getMeters()).hasSize(2); assertThat(registry.getMeters().get(0).getId().getTags()).hasSize(2); // version + key0 }
Example #10
Source File: MeterMapCleanerTask.java From summerframework with Apache License 2.0 | 6 votes |
public static void main(String[] args) { SimpleMeterRegistry meterRegistry = new SimpleMeterRegistry(); Metrics.globalRegistry.add(meterRegistry); MeterMapCleanerTask task = new MeterMapCleanerTask(Metrics.globalRegistry); task.start("0/2 * * * * ?"); ScheduledExecutorService s = Executors.newSingleThreadScheduledExecutor(); s.scheduleAtFixedRate(() -> { meterRegistry.counter(UUID.randomUUID().toString()).increment(); System.out.println(meterRegistry.getMeters().size()); }, 0, 100, TimeUnit.MILLISECONDS); try { TimeUnit.SECONDS.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } s.shutdown(); task.stop(); }
Example #11
Source File: GatewaySocketAcceptorTests.java From spring-cloud-rsocket with Apache License 2.0 | 6 votes |
@Before public void init() { this.factory = mock(GatewayRSocketFactory.class); this.setupPayload = mock(ConnectionSetupPayload.class); this.sendingSocket = mock(RSocket.class); this.meterRegistry = new SimpleMeterRegistry(); this.metadataExtractor.metadataToExtract(ROUTE_SETUP_MIME_TYPE, RouteSetup.class, "routesetup"); when(this.factory.create(any(TagsMetadata.class))) .thenReturn(mock(GatewayRSocket.class)); when(this.setupPayload.metadataMimeType()) .thenReturn(Metadata.COMPOSITE_MIME_TYPE.toString()); when(this.setupPayload.hasMetadata()).thenReturn(true); MetadataEncoder encoder = new MetadataEncoder(Metadata.COMPOSITE_MIME_TYPE, this.rSocketStrategies); encoder.metadata(RouteSetup.of(1L, "myservice").build(), ROUTE_SETUP_MIME_TYPE); DataBuffer dataBuffer = encoder.encode(); DataBuffer data = MetadataEncoder.emptyDataBuffer(rSocketStrategies); Payload payload = PayloadUtils.createPayload(data, dataBuffer); when(setupPayload.metadata()).thenReturn(payload.metadata()); }
Example #12
Source File: CaffeineCacheMetricsTest.java From micrometer with Apache License 2.0 | 6 votes |
@Test void reportExpectedGeneralMetrics() { MeterRegistry registry = new SimpleMeterRegistry(); metrics.bindTo(registry); verifyCommonCacheMetrics(registry, metrics); FunctionCounter evictionWeight = fetch(registry, "cache.eviction.weight").functionCounter(); CacheStats stats = cache.stats(); assertThat(evictionWeight.count()).isEqualTo(stats.evictionWeight()); // specific to LoadingCache instance TimeGauge loadDuration = fetch(registry, "cache.load.duration").timeGauge(); assertThat(loadDuration.value()).isEqualTo(stats.totalLoadTime()); FunctionCounter successfulLoad = fetch(registry, "cache.load", Tags.of("result", "success")).functionCounter(); assertThat(successfulLoad.count()).isEqualTo(stats.loadSuccessCount()); FunctionCounter failedLoad = fetch(registry, "cache.load", Tags.of("result", "failure")).functionCounter(); assertThat(failedLoad.count()).isEqualTo(stats.loadFailureCount()); }
Example #13
Source File: KafkaMetricsTest.java From micrometer with Apache License 2.0 | 6 votes |
@Test void shouldRemoveMeterWithLessTags() { Supplier<Map<MetricName, ? extends Metric>> supplier = () -> { MetricName firstName = new MetricName("a", "b", "c", Collections.emptyMap()); KafkaMetric firstMetric = new KafkaMetric(this, firstName, new Value(), new MetricConfig(), Time.SYSTEM); Map<String, String> tags = new LinkedHashMap<>(); tags.put("key0", "value0"); MetricName secondName = new MetricName("a", "b", "c", tags); KafkaMetric secondMetric = new KafkaMetric(this, secondName, new Value(), new MetricConfig(), Time.SYSTEM); Map<MetricName, KafkaMetric> metrics = new LinkedHashMap<>(); metrics.put(firstName, firstMetric); metrics.put(secondName, secondMetric); return metrics; }; kafkaMetrics = new KafkaMetrics(supplier); MeterRegistry registry = new SimpleMeterRegistry(); kafkaMetrics.bindTo(registry); assertThat(registry.getMeters()).hasSize(1); assertThat(registry.getMeters().get(0).getId().getTags()).hasSize(2); // version + key0 }
Example #14
Source File: MeterFilterTest.java From micrometer with Apache License 2.0 | 6 votes |
@Test void mapThenAccept() { MeterRegistry registry = new SimpleMeterRegistry(); registry.config().meterFilter(new MeterFilter() { @Override public Meter.Id map(Meter.Id id) { return id.withName("my.other.counter"); } }); registry.config().meterFilter(MeterFilter.acceptNameStartsWith("my.other")); registry.config().meterFilter(MeterFilter.deny()); registry.counter("my.counter").increment(); assertThat(registry.getMeters()).isNotEmpty(); }
Example #15
Source File: TimedAspectTest.java From micrometer with Apache License 2.0 | 6 votes |
@Test void timeMethodWithLongTaskTimer() { MeterRegistry registry = new SimpleMeterRegistry(); AspectJProxyFactory pf = new AspectJProxyFactory(new TimedService()); pf.addAspect(new TimedAspect(registry)); TimedService service = pf.getProxy(); service.longCall(); assertThat(registry.get("longCall") .tag("class", "io.micrometer.core.aop.TimedAspectTest$TimedService") .tag("method", "longCall") .tag("extra", "tag") .longTaskTimers().size()).isEqualTo(1); }
Example #16
Source File: MetricsCollectorTest.java From rabbitmq-mock with Apache License 2.0 | 6 votes |
@Test void metrics_collector_is_invoked_on_basic_ack() throws IOException, TimeoutException { MockConnectionFactory mockConnectionFactory = new MockConnectionFactory(); SimpleMeterRegistry registry = new SimpleMeterRegistry(); mockConnectionFactory.setMetricsCollector(new MicrometerMetricsCollector(registry)); try (MockConnection connection = mockConnectionFactory.newConnection(); Channel channel = connection.createChannel(42)) { String queueName = channel.queueDeclare().getQueue(); channel.basicPublish("", queueName, null, "".getBytes()); GetResponse getResponse = channel.basicGet(queueName, false); assertThat(registry.get("rabbitmq.acknowledged").counter().count()).isEqualTo(0); channel.basicAck(getResponse.getEnvelope().getDeliveryTag(), false); assertThat(registry.get("rabbitmq.acknowledged").counter().count()).isEqualTo(1); } }
Example #17
Source File: MetricsCollectorTest.java From rabbitmq-mock with Apache License 2.0 | 6 votes |
@Test void metrics_collector_is_invoked_on_basic_nack() throws IOException, TimeoutException { MockConnectionFactory mockConnectionFactory = new MockConnectionFactory(); SimpleMeterRegistry registry = new SimpleMeterRegistry(); mockConnectionFactory.setMetricsCollector(new MicrometerMetricsCollector(registry)); try (MockConnection connection = mockConnectionFactory.newConnection(); Channel channel = connection.createChannel(42)) { String queueName = channel.queueDeclare().getQueue(); channel.basicPublish("", queueName, null, "".getBytes()); GetResponse getResponse = channel.basicGet(queueName, false); assertThat(registry.get("rabbitmq.rejected").counter().count()).isEqualTo(0); channel.basicNack(getResponse.getEnvelope().getDeliveryTag(), false, false); assertThat(registry.get("rabbitmq.rejected").counter().count()).isEqualTo(1); } }
Example #18
Source File: MetricsCollectorTest.java From rabbitmq-mock with Apache License 2.0 | 6 votes |
@Test void metrics_collector_is_invoked_on_basic_reject() throws IOException, TimeoutException { MockConnectionFactory mockConnectionFactory = new MockConnectionFactory(); SimpleMeterRegistry registry = new SimpleMeterRegistry(); mockConnectionFactory.setMetricsCollector(new MicrometerMetricsCollector(registry)); try (MockConnection connection = mockConnectionFactory.newConnection(); Channel channel = connection.createChannel(42)) { String queueName = channel.queueDeclare().getQueue(); channel.basicPublish("", queueName, null, "".getBytes()); GetResponse getResponse = channel.basicGet(queueName, false); assertThat(registry.get("rabbitmq.rejected").counter().count()).isEqualTo(0); channel.basicReject(getResponse.getEnvelope().getDeliveryTag(), false); assertThat(registry.get("rabbitmq.rejected").counter().count()).isEqualTo(1); } }
Example #19
Source File: GaugesTest.java From vertx-micrometer-metrics with Apache License 2.0 | 6 votes |
@Test public void shouldIgnoreGaugeLabel() { MeterRegistry registry = new SimpleMeterRegistry(); BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match() .setLabel("address") .setType(MatchType.REGEX) .setValue(".*") .setAlias("_"))); Gauges<LongAdder> gauges = new Gauges<>("my_gauge", "", LongAdder::new, LongAdder::doubleValue, registry, Label.EB_ADDRESS); gauges.get("addr1").increment(); gauges.get("addr1").increment(); gauges.get("addr2").increment(); Gauge g = registry.find("my_gauge").tags("address", "_").gauge(); assertThat(g.value()).isEqualTo(3d); g = registry.find("my_gauge").tags("address", "addr1").gauge(); assertThat(g).isNull(); g = registry.find("my_gauge").tags("address", "addr2").gauge(); assertThat(g).isNull(); }
Example #20
Source File: NodeHealthCheckServiceTest.java From eventeum with Apache License 2.0 | 6 votes |
@Before public void init() throws Exception { mockBlockchainService = mock(BlockchainService.class); when(mockBlockchainService.getNodeName()).thenReturn(Constants.DEFAULT_NODE_NAME); mockReconnectionStrategy = mock(ReconnectionStrategy.class); mockSubscriptionService = mock(SubscriptionService.class); mockEventStoreService = mock(EventStoreService.class); LatestBlock latestBlock = new LatestBlock(); latestBlock.setNumber(BLOCK_NUMBER); when(mockEventStoreService.getLatestBlock(any())).thenReturn(Optional.of(latestBlock)); mockEventeumValueMonitor = new MicrometerValueMonitor(new SimpleMeterRegistry()); mockTaskScheduler = mock(ScheduledThreadPoolExecutor.class); underTest = createUnderTest(); }
Example #21
Source File: GaugesTest.java From vertx-micrometer-metrics with Apache License 2.0 | 6 votes |
@Test public void shouldAliasGaugeLabel() { MeterRegistry registry = new SimpleMeterRegistry(); BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match() .setLabel("address") .setType(MatchType.REGEX) .setValue("addr1") .setAlias("1"))); Gauges<LongAdder> gauges = new Gauges<>("my_gauge", "", LongAdder::new, LongAdder::doubleValue, registry, Label.EB_ADDRESS); gauges.get("addr1").increment(); gauges.get("addr1").increment(); gauges.get("addr2").increment(); Gauge g = registry.find("my_gauge").tags("address", "1").gauge(); assertThat(g.value()).isEqualTo(2d); g = registry.find("my_gauge").tags("address", "addr1").gauge(); assertThat(g).isNull(); g = registry.find("my_gauge").tags("address", "addr2").gauge(); assertThat(g.value()).isEqualTo(1d); }
Example #22
Source File: SummariesTest.java From vertx-micrometer-metrics with Apache License 2.0 | 6 votes |
@Test public void shouldIgnoreSummaryLabel() { MeterRegistry registry = new SimpleMeterRegistry(); BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match() .setLabel("address") .setType(MatchType.REGEX) .setValue(".*") .setAlias("_"))); Summaries summaries = new Summaries("my_summary", "", registry, Label.EB_ADDRESS); summaries.get("addr1").record(5); summaries.get("addr1").record(8); summaries.get("addr2").record(10); DistributionSummary s = registry.find("my_summary").tags("address", "_").summary(); assertThat(s.count()).isEqualTo(3); assertThat(s.totalAmount()).isEqualTo(23); s = registry.find("my_summary").tags("address", "addr1").summary(); assertThat(s).isNull(); s = registry.find("my_summary").tags("address", "addr2").summary(); assertThat(s).isNull(); }
Example #23
Source File: SummariesTest.java From vertx-micrometer-metrics with Apache License 2.0 | 6 votes |
@Test public void shouldAliasSummaryLabel() { MeterRegistry registry = new SimpleMeterRegistry(); BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match() .setLabel("address") .setType(MatchType.REGEX) .setValue("addr1") .setAlias("1"))); Summaries summaries = new Summaries("my_summary", "", registry, Label.EB_ADDRESS); summaries.get("addr1").record(5); summaries.get("addr1").record(8); summaries.get("addr2").record(10); DistributionSummary s = registry.find("my_summary").tags("address", "1").summary(); assertThat(s.count()).isEqualTo(2); assertThat(s.totalAmount()).isEqualTo(13); s = registry.find("my_summary").tags("address", "addr1").summary(); assertThat(s).isNull(); s = registry.find("my_summary").tags("address", "addr2").summary(); assertThat(s.count()).isEqualTo(1); assertThat(s.totalAmount()).isEqualTo(10); }
Example #24
Source File: CountersTest.java From vertx-micrometer-metrics with Apache License 2.0 | 6 votes |
@Test public void shouldAliasCounterLabel() { MeterRegistry registry = new SimpleMeterRegistry(); BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match() .setLabel("address") .setType(MatchType.REGEX) .setValue("addr1") .setAlias("1"))); Counters counters = new Counters("my_counter", "", registry, Label.EB_ADDRESS); counters.get("addr1").increment(); counters.get("addr1").increment(); counters.get("addr2").increment(); Counter c = registry.find("my_counter").tags("address", "1").counter(); assertThat(c.count()).isEqualTo(2d); c = registry.find("my_counter").tags("address", "addr1").counter(); assertThat(c).isNull(); c = registry.find("my_counter").tags("address", "addr2").counter(); assertThat(c.count()).isEqualTo(1d); }
Example #25
Source File: CommonsObjectPool2MetricsTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void metricsReportedPerMultiplePools() { createGenericObjectPool(); createGenericObjectPool(); createGenericObjectPool(); MeterRegistry registry = new SimpleMeterRegistry(); commonsObjectPool2Metrics.bindTo(registry); registry.get("commons.pool2.num.waiters").tag("name", "pool" + genericObjectPoolCount).gauge(); registry.get("commons.pool2.num.waiters").tag("name", "pool" + (genericObjectPoolCount - 1)).gauge(); }
Example #26
Source File: DatadogMetricMetadataTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void escapesStringsInDescription() { DatadogMetricMetadata metricMetadata = new DatadogMetricMetadata( Counter.builder("name") .tag("key", "value") .description("The /\"recent cpu usage\" for the Java Virtual Machine process") .register(new SimpleMeterRegistry()).getId(), true ); assertThat(metricMetadata.editDescriptionMetadataBody()).isEqualTo("{\"description\":\"The /\\\"recent cpu usage\\\" for the Java Virtual Machine process\"}"); }
Example #27
Source File: MetricCollectingClientInterceptorTest.java From grpc-spring-boot-starter with MIT License | 5 votes |
@Test public void testClientPreRegistration() { log.info("--- Starting tests with client pre-registration ---"); final MeterRegistry meterRegistry = new SimpleMeterRegistry(); assertEquals(0, meterRegistry.getMeters().size()); final MetricCollectingClientInterceptor mcci = new MetricCollectingClientInterceptor(meterRegistry); mcci.preregisterService(TestServiceGrpc.getServiceDescriptor()); MetricTestHelper.logMeters(meterRegistry.getMeters()); assertEquals(METHOD_COUNT * 3, meterRegistry.getMeters().size()); log.info("--- Test completed ---"); }
Example #28
Source File: CaffeineCacheMetricsTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void doNotReportMetricsForNonLoadingCache() { MeterRegistry meterRegistry = new SimpleMeterRegistry(); Cache<Object, Object> cache = Caffeine.newBuilder().build(); CaffeineCacheMetrics metrics = new CaffeineCacheMetrics(cache, "testCache", expectedTag); metrics.bindTo(meterRegistry); assertThat(meterRegistry.find("cache.load.duration").timeGauge()).isNull(); }
Example #29
Source File: KafkaClientMetricsConsumerTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void shouldCreateMetersWithTags() { try (Consumer<String, String> consumer = createConsumer()) { metrics = new KafkaClientMetrics(consumer, tags); MeterRegistry registry = new SimpleMeterRegistry(); metrics.bindTo(registry); assertThat(registry.getMeters()) .hasSizeGreaterThan(0) .extracting(meter -> meter.getId().getTag("app")) .allMatch(s -> s.equals("myapp")); } }
Example #30
Source File: CommonsObjectPool2MetricsTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void newPoolsAreDiscoveredByListener() throws InterruptedException { MeterRegistry registry = new SimpleMeterRegistry(); commonsObjectPool2Metrics.bindTo(registry); CountDownLatch latch = new CountDownLatch(1); registry.config().onMeterAdded(m -> { if (m.getId().getName().contains("commons.pool2")) latch.countDown(); }); createGenericObjectPool(); latch.await(10, TimeUnit.SECONDS); }