void onRequestRejected() { rejectedRequests.increment(); } }
@TearDown(Level.Trial) public void tearDown(Blackhole hole) { for (io.micrometer.core.instrument.Meter m : registry.getMeters()) { if (m instanceof io.micrometer.core.instrument.Counter) { hole.consume(((io.micrometer.core.instrument.Counter) m).count()); } } } }
@Nullable private Optional<String> writeCounter(Counter counter) { double count = counter.count(); if (count > 0) { // can't use "count" field because sum is required whenever count is set. return Optional.of(write(counter.getId(), "counter", Fields.Value.tag(), decimal(count))); } return Optional.empty(); }
protected MicroCounterBuilder(MeterRegistry meterRegistry, String name) { this.meterRegistry = meterRegistry; this.builder = Counter.builder(name); }
@Override public String getName() { return counter.getId().getName(); }
@Test @DisplayName("find meters by name and value") void findMetersByValue(MeterRegistry registry) { Counter c = registry.counter("counter"); c.increment(); Timer t = registry.timer("timer"); t.record(10, TimeUnit.NANOSECONDS); clock(registry).add(step()); assertThat(registry.get("counter").counter().count()).isEqualTo(1.0); assertThat(registry.get("timer").timer().count()).isEqualTo(1L); assertThat(registry.get("timer").timer().totalTime(TimeUnit.NANOSECONDS)).isEqualTo(10.0); }
.builder(FluxMetrics.METER_SUBSCRIBED) .tags(commonTags) .baseUnit("subscribers")
@Test public void testClientCustomization() { log.info("--- Starting tests with client customization ---"); final MeterRegistry meterRegistry = new SimpleMeterRegistry(); assertEquals(0, meterRegistry.getMeters().size()); final MetricCollectingClientInterceptor mcci = new MetricCollectingClientInterceptor(meterRegistry, counter -> counter.tag("type", "counter"), timer -> timer.tag("type", "timer").publishPercentiles(0.5, 0.9, 0.99), OK, UNKNOWN); mcci.preregisterService(TestServiceGrpc.getServiceDescriptor()); MetricTestHelper.logMeters(meterRegistry.getMeters()); assertEquals(METHOD_COUNT * 10, meterRegistry.getMeters().size()); final Counter counter = meterRegistry.find(METRIC_NAME_CLIENT_REQUESTS_SENT).counter(); assertNotNull(counter); assertEquals("counter", counter.getId().getTag("type")); final Timer timer = meterRegistry.find(METRIC_NAME_CLIENT_PROCESSING_DURATION).timer(); assertNotNull(timer); assertEquals("timer", timer.getId().getTag("type")); log.info("--- Test completed ---"); }
@Override public void recordConnectionTimeout() { connectionTimeoutCounter.increment(); }
@Test public void countsSubscriptionsFuseable() { Mono<Integer> source = Mono.just(10); Mono<Integer> test = new MonoMetricsFuseable<>(source, registry); test.subscribe(); Counter meter = registry.find(METER_SUBSCRIBED) .counter(); assertThat(meter).isNotNull(); assertThat(meter.count()).as("after 1s subscribe").isEqualTo(1); test.subscribe(); test.subscribe(); assertThat(meter.count()).as("after more subscribe").isEqualTo(3); }
.builder(METER_SUBSCRIBED) .tags(commonTags) .baseUnit("subscribers")
@Test public void testServerCustomization() { log.info("--- Starting tests with server customization ---"); final MeterRegistry meterRegistry = new SimpleMeterRegistry(); assertEquals(0, meterRegistry.getMeters().size()); final MetricCollectingServerInterceptor mcsi = new MetricCollectingServerInterceptor(meterRegistry, counter -> counter.tag("type", "counter"), timer -> timer.tag("type", "timer").publishPercentiles(0.5, 0.9, 0.99), OK, UNKNOWN); mcsi.preregisterService(new TestServiceImpl()); MetricTestHelper.logMeters(meterRegistry.getMeters()); assertEquals(METHOD_COUNT * 10, meterRegistry.getMeters().size()); final Counter counter = meterRegistry.find(METRIC_NAME_SERVER_REQUESTS_RECEIVED).counter(); assertNotNull(counter); assertEquals("counter", counter.getId().getTag("type")); final Timer timer = meterRegistry.find(METRIC_NAME_SERVER_PROCESSING_DURATION).timer(); assertNotNull(timer); assertEquals("timer", timer.getId().getTag("type")); log.info("--- Test completed ---"); }
public void micrometerCounter(MicrometerState state) { state.counter.increment(); }
@Test public void countsSubscriptions() { Mono<Integer> source = Mono.just(1) .hide(); Mono<Integer> test = new MonoMetrics<>(source, registry); test.subscribe(); Counter meter = registry.find(METER_SUBSCRIBED) .counter(); assertThat(meter).isNotNull(); assertThat(meter.count()).as("after 1s subscribe").isEqualTo(1); test.subscribe(); test.subscribe(); assertThat(meter.count()).as("after more subscribe").isEqualTo(3); }
.register(meterRegistry); this.connectionTimeoutCounter = Counter.builder(METRIC_NAME_TIMEOUT_RATE) .description("Connection timeout total count") .tags(METRIC_CATEGORY, poolName)
@Override public List<Context> getContext() { return counter.getId().getTags() .stream() .map(t -> new ContextImpl(t.getKey(), t.getValue())) .collect(Collectors.toList()); }
public void micrometerCounterFixedTags(MicrometerState state) { state.counterWithTags.increment(); }
@Test public void malformedOnComplete() { TestPublisher<Integer> testPublisher = TestPublisher.createNoncompliant(CLEANUP_ON_TERMINATE); Mono<Integer> source = testPublisher.mono().hide(); new MonoMetrics<>(source, registry) .subscribe(v -> assertThat(v).isEqualTo(1), e -> assertThat(e).hasMessage("malformedOnComplete")); testPublisher.error(new IllegalStateException("malformedOnComplete")) .complete(); Counter malformedMeter = registry .find(METER_MALFORMED) .counter(); assertThat(malformedMeter).isNotNull(); assertThat(malformedMeter.count()).isEqualTo(1); }
/** * Creates a new counter builder for the given method. By default the base unit will be messages. * * @param method The method the counter will be created for. * @param name The name of the counter to use. * @param description The description of the counter to use. * @return The newly created counter builder. */ public static Counter.Builder prepareCounterFor(final MethodDescriptor<?, ?> method, final String name, final String description) { return Counter.builder(name) .description(description) .baseUnit("messages") .tag(TAG_SERVICE_NAME, extractServiceName(method)) .tag(TAG_METHOD_NAME, extractMethodName(method)); }