io.micrometer.core.instrument.Counter类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(468)

本文整理了Java中io.micrometer.core.instrument.Counter类的一些代码示例,展示了Counter类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Counter类的具体详情如下:
包路径:io.micrometer.core.instrument.Counter
类名称:Counter

Counter介绍

暂无

代码示例

代码示例来源:origin: line/armeria

void onRequestRejected() {
    rejectedRequests.increment();
  }
}

代码示例来源:origin: micrometer-metrics/micrometer

@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());
      }
    }
  }
}

代码示例来源:origin: io.micrometer/micrometer-test

@Test
@DisplayName("increment by a non-negative amount")
default void incrementAmount(MeterRegistry registry) {
  Counter c = registry.counter("myCounter");
  c.increment(2);
  c.increment(0);
  clock(registry).add(step());
  assertEquals(2L, c.count());
}

代码示例来源:origin: io.micrometer/micrometer-registry-appoptics

@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();
}

代码示例来源:origin: spring-projects/spring-integration

protected MicroCounterBuilder(MeterRegistry meterRegistry, String name) {
  this.meterRegistry = meterRegistry;
  this.builder = Counter.builder(name);
}

代码示例来源:origin: dev.rico/rico-metrics

@Override
public String getName() {
  return counter.getId().getName();
}

代码示例来源:origin: io.micrometer/micrometer-test

@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);
}

代码示例来源:origin: reactor/reactor-core

.builder(FluxMetrics.METER_SUBSCRIBED)
.tags(commonTags)
.baseUnit("subscribers")

代码示例来源:origin: yidongnan/grpc-spring-boot-starter

@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 ---");
}

代码示例来源:origin: com.zaxxer/HikariCP

@Override
public void recordConnectionTimeout()
{
 connectionTimeoutCounter.increment();
}

代码示例来源:origin: reactor/reactor-core

@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);
}

代码示例来源:origin: reactor/reactor-core

.builder(METER_SUBSCRIBED)
.tags(commonTags)
.baseUnit("subscribers")

代码示例来源:origin: yidongnan/grpc-spring-boot-starter

@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 ---");
}

代码示例来源:origin: micrometer-metrics/micrometer

public void micrometerCounter(MicrometerState state) {
  state.counter.increment();
}

代码示例来源:origin: reactor/reactor-core

@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);
}

代码示例来源:origin: com.zaxxer/HikariCP

.register(meterRegistry);
this.connectionTimeoutCounter = Counter.builder(METRIC_NAME_TIMEOUT_RATE)
  .description("Connection timeout total count")
  .tags(METRIC_CATEGORY, poolName)

代码示例来源:origin: dev.rico/rico-metrics

@Override
public List<Context> getContext() {
  return counter.getId().getTags()
      .stream()
      .map(t -> new ContextImpl(t.getKey(), t.getValue()))
      .collect(Collectors.toList());
}

代码示例来源:origin: micrometer-metrics/micrometer

public void micrometerCounterFixedTags(MicrometerState state) {
  state.counterWithTags.increment();
}

代码示例来源:origin: reactor/reactor-core

@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);
}

代码示例来源:origin: yidongnan/grpc-spring-boot-starter

/**
 * 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));
}

相关文章