Search in sources :

Example 6 with Tags

use of io.micrometer.core.instrument.Tags in project feign by OpenFeign.

the class MeteredClient method createTimer.

protected Timer createTimer(Request request, Response response, Options options, Exception e) {
    final RequestTemplate template = request.requestTemplate();
    final Tags allTags = metricTagResolver.tag(template.methodMetadata(), template.feignTarget(), e, Tag.of("uri", template.methodMetadata().template().path())).and(extraTags(request, response, options, e));
    return meterRegistry.timer(metricName.name(e), allTags);
}
Also used : Tags(io.micrometer.core.instrument.Tags)

Example 7 with Tags

use of io.micrometer.core.instrument.Tags in project hono by eclipse.

the class MicrometerBasedMetrics method create.

@Override
public SendMessageSampler create(final String messageType) {
    Objects.requireNonNull(messageType);
    return new SendMessageSampler() {

        @Override
        public Sample start(final String tenantId) {
            final Timer.Sample sample = Timer.start(registry);
            return new Sample() {

                @Override
                public void completed(final String outcome) {
                    final Tags tags = Tags.of(Tag.of(MetricsTags.TAG_TYPE, messageType), MetricsTags.getTenantTag(tenantId), Tag.of("outcome", outcome));
                    sample.stop(registry.timer(METER_DOWNSTREAM_SENT, tags));
                }

                @Override
                public void timeout() {
                    /*
                         * We report timeouts with a different meter, since the message might still be
                         * accepted by the remote peer, at a time after the timeout expired. And so we
                         * can still track those times.
                         */
                    final Tags tags = Tags.of(Tag.of(MetricsTags.TAG_TYPE, messageType), MetricsTags.getTenantTag(tenantId));
                    registry.counter(METER_DOWNSTREAM_TIMEOUT, tags).increment();
                }
            };
        }

        @Override
        public void queueFull(final String tenantId) {
            final Tags tags = Tags.of(Tag.of(MetricsTags.TAG_TYPE, messageType), MetricsTags.getTenantTag(tenantId));
            registry.counter(METER_DOWNSTREAM_FULL, tags).increment();
        }
    };
}
Also used : Timer(io.micrometer.core.instrument.Timer) Sample(io.micrometer.core.instrument.Timer.Sample) SendMessageSampler(org.eclipse.hono.client.SendMessageSampler) Sample(io.micrometer.core.instrument.Timer.Sample) Tags(io.micrometer.core.instrument.Tags)

Example 8 with Tags

use of io.micrometer.core.instrument.Tags in project reactor-core by reactor.

the class MonoMetricsFuseableTest method splitMetricsOnNameFuseable.

@Test
public void splitMetricsOnNameFuseable() {
    final Mono<Integer> unnamedSource = Mono.just(0).map(v -> 100 / v);
    final Mono<Integer> namedSource = Mono.just(0).map(v -> 100 / v).name("foo");
    final Mono<Integer> unnamed = new MonoMetricsFuseable<>(unnamedSource).onErrorResume(e -> Mono.empty());
    final Mono<Integer> named = new MonoMetricsFuseable<>(namedSource).onErrorResume(e -> Mono.empty());
    Mono.when(unnamed, named).block();
    Timer unnamedMeter = registry.find(REACTOR_DEFAULT_NAME + METER_FLOW_DURATION).tags(Tags.of(TAG_ON_ERROR)).tag(TAG_KEY_EXCEPTION, ArithmeticException.class.getName()).timer();
    Timer namedMeter = registry.find("foo" + METER_FLOW_DURATION).tags(Tags.of(TAG_ON_ERROR)).tag(TAG_KEY_EXCEPTION, ArithmeticException.class.getName()).timer();
    assertThat(unnamedMeter).isNotNull();
    assertThat(unnamedMeter.count()).isOne();
    assertThat(namedMeter).isNotNull();
    assertThat(namedMeter.count()).isOne();
}
Also used : Metrics(reactor.util.Metrics) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SoftAssertions(org.assertj.core.api.SoftAssertions) Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) MockClock(io.micrometer.core.instrument.MockClock) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MetricsFuseableSubscriber(reactor.core.publisher.MonoMetricsFuseable.MetricsFuseableSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) CoreSubscriber(reactor.core.CoreSubscriber) Timer(io.micrometer.core.instrument.Timer) Duration(java.time.Duration) Counter(io.micrometer.core.instrument.Counter) Tags(io.micrometer.core.instrument.Tags) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Clock(io.micrometer.core.instrument.Clock) SimpleConfig(io.micrometer.core.instrument.simple.SimpleConfig) TAG_ON_COMPLETE_EMPTY(reactor.core.publisher.FluxMetrics.TAG_ON_COMPLETE_EMPTY) FluxMetrics(reactor.core.publisher.FluxMetrics) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) Fuseable(reactor.core.Fuseable) DistributionSummary(io.micrometer.core.instrument.DistributionSummary) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Timer(io.micrometer.core.instrument.Timer) Test(org.junit.jupiter.api.Test)

Example 9 with Tags

use of io.micrometer.core.instrument.Tags in project open-kilda by telstra.

the class PushToStreamMeterRegistry method writeCustomMeter.

private List<Datapoint> writeCustomMeter(Meter meter) {
    long wallTime = config().clock().wallTime();
    List<Tag> tags = getConventionTags(meter.getId());
    return StreamSupport.stream(meter.measure().spliterator(), false).map(ms -> {
        String name = getConventionName(meter.getId());
        switch(ms.getStatistic()) {
            case TOTAL:
            case TOTAL_TIME:
                name += ".sum";
                break;
            case MAX:
                name += ".max";
                break;
            case ACTIVE_TASKS:
                name += ".active.count";
                break;
            case DURATION:
                name += ".duration.sum";
                break;
            default:
                throw new IllegalStateException("Unknown statistic " + ms.getStatistic());
        }
        Datapoint datapoint = new Datapoint();
        datapoint.setMetric(name);
        datapoint.setTime(wallTime);
        // Double type is not supported by {@link org.apache.storm.opentsdb.OpenTsdbMetricDatapoint}
        datapoint.setValue((long) ms.getValue());
        Tags localTags = Tags.concat(tags, "statistics", ms.getStatistic().toString());
        Map<String, String> resultTags = new HashMap<>(localTags.stream().collect(Collectors.toMap(Tag::getKey, Tag::getValue)));
        if (resultTags.isEmpty()) {
            // FIXME: opentsdb rejects datapoints without tags.
            resultTags.put("dummy", "dummy");
        }
        datapoint.setTags(resultTags);
        return datapoint;
    }).collect(Collectors.toList());
}
Also used : LongTaskTimer(io.micrometer.core.instrument.LongTaskTimer) TimeGauge(io.micrometer.core.instrument.TimeGauge) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Timer(io.micrometer.core.instrument.Timer) DistributionStatisticConfig(io.micrometer.core.instrument.distribution.DistributionStatisticConfig) OutputCollector(org.apache.storm.task.OutputCollector) DefaultGauge(io.micrometer.core.instrument.internal.DefaultGauge) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) ToLongFunction(java.util.function.ToLongFunction) Utils(org.openkilda.messaging.Utils) Counter(io.micrometer.core.instrument.Counter) Tag(io.micrometer.core.instrument.Tag) Tags(io.micrometer.core.instrument.Tags) Nullable(io.micrometer.core.lang.Nullable) DatapointEntries(org.openkilda.messaging.info.DatapointEntries) Clock(io.micrometer.core.instrument.Clock) Gauge(io.micrometer.core.instrument.Gauge) PauseDetector(io.micrometer.core.instrument.distribution.pause.PauseDetector) Meter(io.micrometer.core.instrument.Meter) CumulativeCounter(io.micrometer.core.instrument.cumulative.CumulativeCounter) Datapoint(org.openkilda.messaging.info.Datapoint) FunctionTimer(io.micrometer.core.instrument.FunctionTimer) Collectors(java.util.stream.Collectors) Measurement(io.micrometer.core.instrument.Measurement) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) DistributionSummary(io.micrometer.core.instrument.DistributionSummary) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ToDoubleFunction(java.util.function.ToDoubleFunction) NamingConvention(io.micrometer.core.instrument.config.NamingConvention) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) DefaultLongTaskTimer(io.micrometer.core.instrument.internal.DefaultLongTaskTimer) Pattern(java.util.regex.Pattern) DefaultMeter(io.micrometer.core.instrument.internal.DefaultMeter) Collections(java.util.Collections) Datapoint(org.openkilda.messaging.info.Datapoint) Tag(io.micrometer.core.instrument.Tag) HashMap(java.util.HashMap) Map(java.util.Map) Tags(io.micrometer.core.instrument.Tags)

Example 10 with Tags

use of io.micrometer.core.instrument.Tags in project spring-boot by spring-projects.

the class StartupTimeMetricsListenerTests method metricRecordedWithoutMainAppClassTagAndAdditionalTags.

@Test
void metricRecordedWithoutMainAppClassTagAndAdditionalTags() {
    SpringApplication application = mock(SpringApplication.class);
    Tags tags = Tags.of("foo", "bar");
    this.listener = new StartupTimeMetricsListener(this.registry, "started", "ready", tags);
    this.listener.onApplicationEvent(new ApplicationReadyEvent(application, null, null, Duration.ofSeconds(2)));
    TimeGauge applicationReadyGague = this.registry.find("ready").timeGauge();
    assertThat(applicationReadyGague).isNotNull();
    assertThat(applicationReadyGague.getId().getTags()).containsExactlyElementsOf(tags);
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) TimeGauge(io.micrometer.core.instrument.TimeGauge) Tags(io.micrometer.core.instrument.Tags) Test(org.junit.jupiter.api.Test)

Aggregations

Tags (io.micrometer.core.instrument.Tags)26 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)10 Test (org.junit.jupiter.api.Test)9 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 Timer (io.micrometer.core.instrument.Timer)6 Clock (io.micrometer.core.instrument.Clock)5 Counter (io.micrometer.core.instrument.Counter)5 DistributionSummary (io.micrometer.core.instrument.DistributionSummary)5 TimeUnit (java.util.concurrent.TimeUnit)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 MockClock (io.micrometer.core.instrument.MockClock)4 SimpleConfig (io.micrometer.core.instrument.simple.SimpleConfig)4 Duration (java.time.Duration)4 Scannable (reactor.core.Scannable)4 Metrics (reactor.util.Metrics)4 Sample (io.micrometer.core.instrument.Timer.Sample)3 Vertx (io.vertx.core.Vertx)3 File (java.io.File)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatCode (org.assertj.core.api.Assertions.assertThatCode)3