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

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

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

Timer.start介绍

暂无

代码示例

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

@Benchmark
public int sumTimedWithSample() {
  Timer.Sample sample = Timer.start(registry);
  int sum = sum();
  sample.stop(timer);
  return sum;
}

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

@Override
public void onSubscribe(Subscription s) {
  if (Operators.validate(this.s, s)) {
    this.subscribedCounter.increment();
    this.subscribeToTerminateSample = Timer.start(clock);
    if (s instanceof Fuseable.QueueSubscription) {
      //noinspection unchecked
      this.qs = (Fuseable.QueueSubscription<T>) s;
    }
    this.s = s;
    actual.onSubscribe(this);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-gateway

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
  Sample sample = Timer.start(meterRegistry);
  return chain.filter(exchange).doOnSuccessOrError((aVoid, ex) -> {
    endTimerRespectingCommit(exchange, sample);
  });
}

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

@Override
public void onSubscribe(Subscription s) {
  if (Operators.validate(this.s, s)) {
    this.subscribedCounter.increment();
    this.subscribeToTerminateSample = Timer.start(clock);
    this.lastNextEventNanos = clock.monotonicTime();
    if (s instanceof Fuseable.QueueSubscription) {
      //noinspection unchecked
      this.qs = (Fuseable.QueueSubscription<T>) s;
    }
    this.s = s;
    actual.onSubscribe(this);
  }
}

代码示例来源:origin: rsocket/rsocket-java

Sample start() {
 return Timer.start(meterRegistry);
}

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

/**
 * Creates a new delegating ServerCall that will wrap the given server call to collect metrics.
 *
 * @param delegate The original call to wrap.
 * @param registry The registry to save the metrics to.
 * @param responseCounter The counter for incoming responses.
 * @param timerFunction A function that will return a timer for a given status code.
 */
public MetricCollectingServerCall(final ServerCall<Q, A> delegate, final MeterRegistry registry,
    final Counter responseCounter,
    final Function<Code, Timer> timerFunction) {
  super(delegate);
  this.responseCounter = responseCounter;
  this.timerFunction = timerFunction;
  this.timerSample = Timer.start(registry);
}

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

/**
 * Creates a new delegating ClientCallListener that will wrap the given client call listener to collect metrics.
 *
 * @param delegate The original call to wrap.
 * @param registry The registry to save the metrics to.
 * @param responseCounter The counter for incoming responses.
 * @param timerFunction A function that will return a timer for a given status code.
 */
public MetricCollectingClientCallListener(
    final ClientCall.Listener<A> delegate,
    final MeterRegistry registry,
    final Counter responseCounter,
    final Function<Code, Timer> timerFunction) {
  super(delegate);
  this.responseCounter = responseCounter;
  this.timerFunction = timerFunction;
  this.timerSample = Timer.start(registry);
}

代码示例来源: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: spring-projects/spring-integration

@Override
public SampleFacade start() {
  return new MicroSample(Timer.start(this.meterRegistry));
}

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

private TimingContext startAndAttachTimingContext(HttpServletRequest request) {
  Timer.Sample timerSample = Timer.start(this.registry);
  TimingContext timingContext = new TimingContext(timerSample);
  timingContext.attachTo(request);
  return timingContext;
}

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

public MicrometerMessageHistory(MeterRegistry meterRegistry, Route route, NamedNode namedNode, MicrometerMessageHistoryNamingStrategy namingStrategy, long timestamp) {
  super(route.getId(), namedNode, timestamp);
  this.meterRegistry = meterRegistry;
  this.route = route;
  this.namingStrategy = namingStrategy;
  this.sample = Timer.start(meterRegistry);
}

代码示例来源:origin: org.zalando/riptide-failsafe

@API(status = INTERNAL)
MetricsCircuitBreakerListener(final MeterRegistry registry, final String metricName,
    final ImmutableList<Tag> defaultTags) {
  this.registry = registry;
  this.metricName = metricName;
  this.defaultTags = defaultTags;
  this.sample = new AtomicReference<>(start(registry));
}

代码示例来源:origin: org.zalando/riptide-failsafe

private void on(final State to) {
  final State from = state.getAndSet(to);
  final Sample last = sample.getAndSet(start(registry));
  if (from != CLOSED) {
    last.stop(registry.timer(metricName, tags(from)));
  }
}

代码示例来源:origin: zalando/riptide

private void on(final State to) {
  final State from = state.getAndSet(to);
  final Sample last = sample.getAndSet(start(registry));
  if (from != CLOSED) {
    last.stop(registry.timer(metricName, tags(from)));
  }
}

代码示例来源:origin: codecentric/spring-boot-starter-batch-web

protected Object profileMethod(ProceedingJoinPoint pjp) throws Throwable {
  Timer.Sample sample = Timer.start(meterRegistry);
  try {
    return pjp.proceed();
  } finally {
    sample.stop(meterRegistry.timer(MetricsListener.METRIC_NAME, Arrays.asList(//
        new ImmutableTag("context", getStepIdentifier()), //
        new ImmutableTag("method", ClassUtils.getShortName(pjp.getTarget().getClass()) + "."
            + pjp.getSignature().getName()))));
  }
}

代码示例来源:origin: de.codecentric/batch-web-spring-boot-autoconfigure

protected Object profileMethod(ProceedingJoinPoint pjp) throws Throwable {
  Timer.Sample sample = Timer.start(meterRegistry);
  try {
    return pjp.proceed();
  } finally {
    sample.stop(meterRegistry.timer(MetricsListener.METRIC_NAME, Arrays.asList(//
        new ImmutableTag("context", getStepIdentifier()), //
        new ImmutableTag("method", ClassUtils.getShortName(pjp.getTarget().getClass()) + "."
            + pjp.getSignature().getName()))));
  }
}

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

void handleStart(Exchange exchange, MeterRegistry registry, String metricsName) {
  String propertyName = getPropertyName(metricsName);
  Timer.Sample sample = getTimerSampleFromExchange(exchange, propertyName);
  if (sample == null) {
    sample = Timer.start(registry);
    exchange.setProperty(propertyName, sample);
  } else {
    LOG.warn("Timer \"{}\" already running", metricsName);
  }
}

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

TimingSampleContext(HttpServletRequest request, Object handlerObject) {
  timedAnnotations = annotations(handlerObject);
  timerSample = Timer.start(registry);
  longTaskTimerSamples = timedAnnotations.stream()
    .filter(Timed::longTask)
    .map(t -> LongTaskTimer.builder(t)
      .tags(tagsProvider.httpLongRequestTags(request, handlerObject))
      .register(registry)
      .start())
    .collect(Collectors.toList());
}

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

@Override
public void onSubscribe(Subscription s) {
  if (Operators.validate(this.s, s)) {
    this.subscribedCounter.increment();
    this.subscribeToTerminateSample = Timer.start(clock);
    if (s instanceof Fuseable.QueueSubscription) {
      //noinspection unchecked
      this.qs = (Fuseable.QueueSubscription<T>) s;
    }
    this.s = s;
    actual.onSubscribe(this);
  }
}

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

@Test
@DisplayName("record with stateful Sample instance")
default void recordWithSample(MeterRegistry registry) {
  Timer timer = registry.timer("myTimer");
  Timer.Sample sample = Timer.start(registry);
  clock(registry).add(10, TimeUnit.NANOSECONDS);
  sample.stop(timer);
  clock(registry).add(step());
  assertAll(() -> assertEquals(1L, timer.count()),
      () -> assertEquals(10, timer.totalTime(TimeUnit.NANOSECONDS), 1.0e-12));
}

相关文章