io.micrometer.core.instrument.Timer.builder()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(391)

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

Timer.builder介绍

暂无

代码示例

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

/**
 * Returns a newly-registered {@link Timer} with percentile publication configured.
 * @deprecated Use {@link #newTimer(MeterRegistry, String, Iterable)}.
 */
@Deprecated
public static Timer timerWithDefaultQuantiles(MeterRegistry registry, String name, Iterable<Tag> tags) {
  requireNonNull(registry, "registry");
  requireNonNull(name, "name");
  requireNonNull(tags, "tags");
  return Timer.builder(name)
        .tags(tags)
        .publishPercentiles(PERCENTILES)
        .register(registry);
}

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

/**
 * Returns a newly-registered {@link Timer} configured by {@link #distributionStatisticConfig()}.
 */
public static Timer newTimer(MeterRegistry registry, String name, Iterable<Tag> tags) {
  requireNonNull(registry, "registry");
  requireNonNull(name, "name");
  requireNonNull(tags, "tags");
  final Duration maxExpectedValue =
      Optional.ofNullable(distStatCfg.getMaximumExpectedValue())
          .map(Duration::ofNanos).orElse(null);
  final Duration minExpectedValue =
      Optional.ofNullable(distStatCfg.getMinimumExpectedValue())
          .map(Duration::ofNanos).orElse(null);
  return Timer.builder(name)
        .tags(tags)
        .maximumExpectedValue(maxExpectedValue)
        .minimumExpectedValue(minExpectedValue)
        .publishPercentiles(distStatCfg.getPercentiles())
        .publishPercentileHistogram(distStatCfg.isPercentileHistogram())
        .distributionStatisticBufferLength(distStatCfg.getBufferLength())
        .distributionStatisticExpiry(distStatCfg.getExpiry())
        .register(registry);
}

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

.builder(FluxMetrics.METER_FLOW_DURATION)
    .tags(commonTags)
    .tag(FluxMetrics.TAG_STATUS, FluxMetrics.TAGVALUE_ON_COMPLETE)
    .register(registry);
this.subscribeToCancelTimer = Timer
    .builder(FluxMetrics.METER_FLOW_DURATION)
    .tags(commonTags)
    .tag(FluxMetrics.TAG_STATUS, FluxMetrics.TAGVALUE_CANCEL)
    .builder(FluxMetrics.METER_FLOW_DURATION)
    .tags(commonTags)
    .tag(FluxMetrics.TAG_STATUS, FluxMetrics.TAGVALUE_ON_ERROR)

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

.builder(METER_FLOW_DURATION)
    .tags(commonTags)
    .tag(TAG_STATUS, TAGVALUE_ON_COMPLETE)
    .register(registry);
this.subscribeToCancelTimer = Timer
    .builder(METER_FLOW_DURATION)
    .tags(commonTags)
    .tag(TAG_STATUS, TAGVALUE_CANCEL)
    .builder(METER_FLOW_DURATION)
    .tags(commonTags)
    .tag(TAG_STATUS, TAGVALUE_ON_ERROR)
    .builder(METER_ON_NEXT_DELAY)
    .tags(commonTags)
    .description("Measures delays between onNext signals (or between onSubscribe and first onNext)")

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

MicroTimerBuilder(MeterRegistry meterRegistry, String name) {
  this.meterRegistry = meterRegistry;
  this.builder = Timer.builder(name);
}

代码示例来源:origin: jooby-project/jooby

public Sample start(MeterRegistry registry) {
 if (longTask) {
  LongTaskTimer.Sample sample = LongTaskTimer.builder(name)
    .description(description)
    .tags(tags)
    .register(registry)
    .start();
  return () -> sample.stop();
 }
 Timer.Sample sample = Timer.start(registry);
 Timer timer = Timer.builder(name)
   .description(description)
   .tags(tags)
   .publishPercentileHistogram(histogram)
   .publishPercentiles(percentiles)
   .register(registry);
 return () -> sample.stop(timer);
}

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

this.connectionObtainTimer = Timer.builder(METRIC_NAME_WAIT)
  .description("Connection acquire time")
  .tags(METRIC_CATEGORY, poolName)
  .register(meterRegistry);
this.connectionCreation = Timer.builder(METRIC_NAME_CONNECT)
  .description("Connection creation time")
  .tags(METRIC_CATEGORY, poolName)
  .register(meterRegistry);
this.connectionUsage = Timer.builder(METRIC_NAME_USAGE)
  .description("Connection usage time")
  .tags(METRIC_CATEGORY, poolName)

代码示例来源:origin: org.springframework.boot/spring-boot-actuator

private Timer.Builder getTimeBuilder(HttpRequest request,
    ClientHttpResponse response) {
  return Timer.builder(this.metricName)
      .tags(this.tagProvider.getTags(urlTemplate.get(), request, response))
      .description("Timer of RestTemplate operation");
}

代码示例来源:origin: org.springframework.boot/spring-boot-actuator

private void record(TimingContext timingContext, HttpServletResponse response,
    HttpServletRequest request, Throwable exception) {
  Object handlerObject = request
      .getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
  Set<Timed> annotations = getTimedAnnotations(handlerObject);
  Timer.Sample timerSample = timingContext.getTimerSample();
  Supplier<Iterable<Tag>> tags = () -> this.tagsProvider.getTags(request, response,
      handlerObject, exception);
  if (annotations.isEmpty()) {
    if (this.autoTimeRequests) {
      stop(timerSample, tags, Timer.builder(this.metricName));
    }
  }
  else {
    for (Timed annotation : annotations) {
      stop(timerSample, tags, Timer.builder(annotation, this.metricName));
    }
  }
}

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

/**
 * Creates a new timer builder for the given method.
 *
 * @param method The method the timer will be created for.
 * @param name The name of the timer to use.
 * @param description The description of the timer to use.
 * @return The newly created timer builder.
 */
public static Timer.Builder prepareTimerFor(final MethodDescriptor<?, ?> method,
    final String name, final String description) {
  return Timer.builder(name)
      .description(description)
      .tag(TAG_SERVICE_NAME, extractServiceName(method))
      .tag(TAG_METHOD_NAME, extractMethodName(method));
}

代码示例来源:origin: org.springframework.boot/spring-boot-actuator

@Override
public Mono<ClientResponse> filter(ClientRequest clientRequest,
    ExchangeFunction exchangeFunction) {
  return exchangeFunction.exchange(clientRequest).doOnEach((signal) -> {
    if (!signal.isOnComplete()) {
      Long startTime = signal.getContext().get(METRICS_WEBCLIENT_START_TIME);
      ClientResponse clientResponse = signal.get();
      Throwable throwable = signal.getThrowable();
      Iterable<Tag> tags = this.tagProvider.tags(clientRequest, clientResponse,
          throwable);
      Timer.builder(this.metricName).tags(tags)
          .description("Timer of WebClient operation")
          .register(this.meterRegistry)
          .record(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
    }
  }).subscriberContext((context) -> context.put(METRICS_WEBCLIENT_START_TIME,
      System.nanoTime()));
}

代码示例来源:origin: org.slinkyframework/slinky-common-metrics

private Timer.Builder getTimerBuilder(MethodProceedingJoinPoint methodProceedingJoinPoint, Throwable throwable) {
  return Timer.builder(format(METRIC_NAME, getComponentType()))
      .tags(createTags(methodProceedingJoinPoint, throwable))
      .description(format("Timer of %s operations", getComponentType()));
}

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

@Deprecated
  @Test
  default void histogramCounts(MeterRegistry registry) {
    Timer t = Timer.builder("my.timer")
        .sla(Duration.ofMillis(1))
        .register(registry);

    t.record(1, TimeUnit.MILLISECONDS);
    assertThat(t.histogramCountAtValue((long) millisToUnit(1, TimeUnit.NANOSECONDS))).isEqualTo(1);
    assertThat(t.histogramCountAtValue(1)).isEqualTo(Double.NaN);
  }
}

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

public Timer get(String... values) {
 // Get or create the Timer
 return Timer.builder(name)
  .description(description)
  .tags(Labels.toTags(keys, values))
  .register(registry);
}

代码示例来源:origin: org.ballerinalang/ballerina-micrometer-extension

public MicrometerTimer(MeterRegistry meterRegistry, MetricId id) {
  super(id);
  timer = io.micrometer.core.instrument.Timer.builder(id.getName())
      .description(id.getDescription())
      .tags(id.getTags().stream().map(tag -> Tag.of(tag.getKey(), tag.getValue()))
          .collect(Collectors.toList()))
      .publishPercentiles(0.5, 0.75, 0.98, 0.99, 0.999)
      .register(meterRegistry);
}

代码示例来源:origin: org.springframework.statemachine/spring-statemachine-autoconfigure

private Timer.Builder getActionTimerBuilder(Action<S, E> action) {
  String actionName = actionToName(action);
  Timer.Builder builder = Timer.builder("ssm.action.duration")
      .tags("actionName", actionName)
      .description("Timer of Action");
  builder.publishPercentileHistogram();
  return builder;
}

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

@Deprecated
@Test
default void percentiles(MeterRegistry registry) {
  Timer t = Timer.builder("my.timer")
      .publishPercentiles(1)
      .register(registry);
  t.record(1, TimeUnit.MILLISECONDS);
  assertThat(t.percentile(1, TimeUnit.MILLISECONDS)).isEqualTo(1, Offset.offset(0.3));
  assertThat(t.percentile(0.5, TimeUnit.MILLISECONDS)).isEqualTo(Double.NaN);
}

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

@Test
@DisplayName("meters with synthetics can be removed without causing deadlocks")
void removeMeterWithSynthetic(MeterRegistry registry) {
  Timer timer = Timer.builder("my.timer")
      .publishPercentiles(0.95)
      .sla(Duration.ofMillis(10))
      .register(registry);
  registry.remove(timer);
}

代码示例来源:origin: org.apache.camel/camel-micrometer

public void onExchangeDone(Exchange exchange) {
  Timer.Sample sample = (Timer.Sample) exchange.removeProperty(propertyName(exchange));
  if (sample != null) {
    Timer timer = Timer.builder(namingStrategy.getName(route))
        .tags(namingStrategy.getTags(route, exchange))
        .description(route.getDescription())
        .register(meterRegistry);
    sample.stop(timer);
  }
}

代码示例来源:origin: org.apache.camel/camel-micrometer

@Override
public void nodeProcessingDone() {
  super.nodeProcessingDone();
  Timer timer = Timer.builder(namingStrategy.getName(route, getNode()))
      .tags(namingStrategy.getTags(route, getNode()))
      .description(getNode().getDescriptionText())
      .register(meterRegistry);
  sample.stop(timer);
}

相关文章