Java Code Examples for io.micrometer.core.instrument.Timer#Builder

The following examples show how to use io.micrometer.core.instrument.Timer#Builder . 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: CompositeTimer.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Override
Timer registerNewMeter(MeterRegistry registry) {
    Timer.Builder builder = Timer.builder(getId().getName())
            .tags(getId().getTagsAsIterable())
            .description(getId().getDescription())
            .maximumExpectedValue(Duration.ofNanos(distributionStatisticConfig.getMaximumExpectedValueAsDouble().longValue()))
            .minimumExpectedValue(Duration.ofNanos(distributionStatisticConfig.getMinimumExpectedValueAsDouble().longValue()))
            .publishPercentiles(distributionStatisticConfig.getPercentiles())
            .publishPercentileHistogram(distributionStatisticConfig.isPercentileHistogram())
            .distributionStatisticBufferLength(distributionStatisticConfig.getBufferLength())
            .distributionStatisticExpiry(distributionStatisticConfig.getExpiry())
            .percentilePrecision(distributionStatisticConfig.getPercentilePrecision())
            .pauseDetector(pauseDetector);

    final double[] sloNanos = distributionStatisticConfig.getServiceLevelObjectiveBoundaries();
    if (sloNanos != null) {
        Duration[] slo = new Duration[sloNanos.length];
        for (int i = 0; i < sloNanos.length; i++) {
            slo[i] = Duration.ofNanos((long) sloNanos[i]);
        }
        builder = builder.serviceLevelObjectives(slo);
    }

    return builder.register(registry);
}
 
Example 2
Source File: MetricUtils.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
/**
 * 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))
            .tag(TAG_METHOD_TYPE, method.getType().name());
}
 
Example 3
Source File: MetricUtils.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
/**
 * 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))
            .tag(TAG_METHOD_TYPE, method.getType().name());
}
 
Example 4
Source File: MetricsClientHttpRequestInterceptor.java    From summerframework with Apache License 2.0 4 votes vote down vote up
private Timer.Builder getTimeBuilder(@Nullable String urlTemplate, HttpRequest request,
    @Nullable ClientHttpResponse response, @Nullable Throwable e) {
    return Timer.builder(this.metricName).tags(Tags.concat(this.tagProvider.getTags(urlTemplate, request, response),
        MicrometerUtil.exceptionAndStatusKey(e))).description("Timer of RestTemplate operation");
}
 
Example 5
Source File: MicrometerMetricsReporter.java    From java-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public void reportSpan(SpanData spanData) {
    boolean skip = Arrays.stream(this.metricLabels).anyMatch(m -> m.value(spanData) == null);
    if (skip) {
        return;
    }

    List<Tag> tags = Arrays.stream(this.metricLabels)
        .map(m -> new ImmutableTag(m.name(), m.value(spanData).toString()))
        .collect(Collectors.toList());

    Timer timer = this.registry.find(this.name).tags(tags).timer();
    if (null != timer) {
        // we have a metric registered already, just record the timing:
        timer.record(spanData.getDuration(), TimeUnit.MICROSECONDS);
        return;
    }

    // would be awesome if we could reuse the builder, but looks like we can't, as we can't override the name
    Timer.Builder builder = Timer.builder(this.name).tags(tags);
    if (publishPercentileHistogram) {
        builder.publishPercentileHistogram();
    }

    if (null != percentiles) {
        builder.publishPercentiles(percentiles);
    }

    if (null != sla) {
        builder.sla(sla);
    }

    if (null != minimumExpectedValue) {
        builder.minimumExpectedValue(minimumExpectedValue);
    }

    if (null != maximumExpectedValue) {
        builder.maximumExpectedValue(maximumExpectedValue);
    }

    builder.register(this.registry).record(spanData.getDuration(), TimeUnit.MICROSECONDS);
}
 
Example 6
Source File: AbstractMetricCollectingInterceptor.java    From grpc-spring-boot-starter with MIT License 3 votes vote down vote up
/**
 * Creates a new gRPC interceptor that will collect metrics into the given {@link MeterRegistry} and uses the given
 * customizer to configure the {@link Counter}s and {@link Timer}s.
 *
 * @param registry The registry to use.
 * @param counterCustomizer The unary function that can be used to customize the created counters.
 * @param timerCustomizer The unary function that can be used to customize the created timers.
 * @param eagerInitializedCodes The status codes that should be eager initialized.
 */
public AbstractMetricCollectingInterceptor(final MeterRegistry registry,
        final UnaryOperator<Counter.Builder> counterCustomizer,
        final UnaryOperator<Timer.Builder> timerCustomizer, final Code... eagerInitializedCodes) {
    this.registry = registry;
    this.counterCustomizer = counterCustomizer;
    this.timerCustomizer = timerCustomizer;
    this.eagerInitializedCodes = eagerInitializedCodes;
}
 
Example 7
Source File: AbstractMetricCollectingInterceptor.java    From grpc-spring-boot-starter with MIT License 3 votes vote down vote up
/**
 * Creates a new gRPC interceptor that will collect metrics into the given {@link MeterRegistry} and uses the given
 * customizer to configure the {@link Counter}s and {@link Timer}s.
 *
 * @param registry The registry to use.
 * @param counterCustomizer The unary function that can be used to customize the created counters.
 * @param timerCustomizer The unary function that can be used to customize the created timers.
 * @param eagerInitializedCodes The status codes that should be eager initialized.
 */
public AbstractMetricCollectingInterceptor(final MeterRegistry registry,
        final UnaryOperator<Counter.Builder> counterCustomizer,
        final UnaryOperator<Timer.Builder> timerCustomizer, final Code... eagerInitializedCodes) {
    this.registry = registry;
    this.counterCustomizer = counterCustomizer;
    this.timerCustomizer = timerCustomizer;
    this.eagerInitializedCodes = eagerInitializedCodes;
}
 
Example 8
Source File: MetricCollectingServerInterceptor.java    From grpc-spring-boot-starter with MIT License 2 votes vote down vote up
/**
 * Creates a new gRPC server interceptor that will collect metrics into the given {@link MeterRegistry} and uses the
 * given customizer to configure the {@link Counter}s and {@link Timer}s.
 *
 * @param registry The registry to use.
 * @param counterCustomizer The unary function that can be used to customize the created counters.
 * @param timerCustomizer The unary function that can be used to customize the created timers.
 * @param eagerInitializedCodes The status codes that should be eager initialized.
 */
public MetricCollectingServerInterceptor(final MeterRegistry registry,
        final UnaryOperator<Counter.Builder> counterCustomizer,
        final UnaryOperator<Timer.Builder> timerCustomizer, final Code... eagerInitializedCodes) {
    super(registry, counterCustomizer, timerCustomizer, eagerInitializedCodes);
}
 
Example 9
Source File: MetricCollectingClientInterceptor.java    From grpc-spring-boot-starter with MIT License 2 votes vote down vote up
/**
 * Creates a new gRPC client interceptor that will collect metrics into the given {@link MeterRegistry} and uses the
 * given customizer to configure the {@link Counter}s and {@link Timer}s.
 *
 * @param registry The registry to use.
 * @param counterCustomizer The unary function that can be used to customize the created counters.
 * @param timerCustomizer The unary function that can be used to customize the created timers.
 * @param eagerInitializedCodes The status codes that should be eager initialized.
 */
public MetricCollectingClientInterceptor(final MeterRegistry registry,
        final UnaryOperator<Counter.Builder> counterCustomizer,
        final UnaryOperator<Timer.Builder> timerCustomizer, final Code... eagerInitializedCodes) {
    super(registry, counterCustomizer, timerCustomizer, eagerInitializedCodes);
}
 
Example 10
Source File: MetricCollectingServerInterceptor.java    From grpc-spring-boot-starter with MIT License 2 votes vote down vote up
/**
 * Creates a new gRPC server interceptor that will collect metrics into the given {@link MeterRegistry} and uses the
 * given customizer to configure the {@link Counter}s and {@link Timer}s.
 *
 * @param registry The registry to use.
 * @param counterCustomizer The unary function that can be used to customize the created counters.
 * @param timerCustomizer The unary function that can be used to customize the created timers.
 * @param eagerInitializedCodes The status codes that should be eager initialized.
 */
public MetricCollectingServerInterceptor(final MeterRegistry registry,
        final UnaryOperator<Counter.Builder> counterCustomizer,
        final UnaryOperator<Timer.Builder> timerCustomizer, final Code... eagerInitializedCodes) {
    super(registry, counterCustomizer, timerCustomizer, eagerInitializedCodes);
}
 
Example 11
Source File: MetricCollectingClientInterceptor.java    From grpc-spring-boot-starter with MIT License 2 votes vote down vote up
/**
 * Creates a new gRPC client interceptor that will collect metrics into the given {@link MeterRegistry} and uses the
 * given customizer to configure the {@link Counter}s and {@link Timer}s.
 *
 * @param registry The registry to use.
 * @param counterCustomizer The unary function that can be used to customize the created counters.
 * @param timerCustomizer The unary function that can be used to customize the created timers.
 * @param eagerInitializedCodes The status codes that should be eager initialized.
 */
public MetricCollectingClientInterceptor(final MeterRegistry registry,
        final UnaryOperator<Counter.Builder> counterCustomizer,
        final UnaryOperator<Timer.Builder> timerCustomizer, final Code... eagerInitializedCodes) {
    super(registry, counterCustomizer, timerCustomizer, eagerInitializedCodes);
}