Search in sources :

Example 1 with TimeGauge

use of io.micrometer.core.instrument.TimeGauge in project micrometer by micrometer-metrics.

the class ElasticMeterRegistryTest method nullGauge.

@Issue("#497")
@Test
void nullGauge() {
    Gauge g = Gauge.builder("gauge", null, o -> 1).register(registry);
    assertThat(registry.writeGauge(g, 0)).isEmpty();
    TimeGauge tg = TimeGauge.builder("time.gauge", null, TimeUnit.MILLISECONDS, o -> 1).register(registry);
    assertThat(registry.writeGauge(tg, 0)).isEmpty();
}
Also used : Counter(io.micrometer.core.instrument.Counter) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Issue(io.micrometer.core.Issue) Gauge(io.micrometer.core.instrument.Gauge) MockClock(io.micrometer.core.instrument.MockClock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeGauge(io.micrometer.core.instrument.TimeGauge) TimeGauge(io.micrometer.core.instrument.TimeGauge) Gauge(io.micrometer.core.instrument.Gauge) TimeGauge(io.micrometer.core.instrument.TimeGauge) Issue(io.micrometer.core.Issue) Test(org.junit.jupiter.api.Test)

Example 2 with TimeGauge

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

the class StartupTimeMetricsListenerTests method metricRecordedWithoutMainAppClassTag.

@Test
void metricRecordedWithoutMainAppClassTag() {
    SpringApplication application = mock(SpringApplication.class);
    this.listener.onApplicationEvent(new ApplicationStartedEvent(application, null, null, Duration.ofSeconds(2)));
    TimeGauge applicationStartedGague = this.registry.find("application.started.time").timeGauge();
    assertThat(applicationStartedGague).isNotNull();
    assertThat(applicationStartedGague.getId().getTags()).isEmpty();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent) TimeGauge(io.micrometer.core.instrument.TimeGauge) Test(org.junit.jupiter.api.Test)

Example 3 with TimeGauge

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

the class StartupTimeMetricsListenerAutoConfigurationTests method startupTimeMetricsAreRecorded.

@Test
void startupTimeMetricsAreRecorded() {
    this.contextRunner.run((context) -> {
        assertThat(context).hasSingleBean(StartupTimeMetricsListener.class);
        SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
        context.publishEvent(new ApplicationStartedEvent(new SpringApplication(), null, context.getSourceApplicationContext(), Duration.ofMillis(1500)));
        TimeGauge startedTimeGage = registry.find("application.started.time").timeGauge();
        assertThat(startedTimeGage).isNotNull();
        assertThat(startedTimeGage.value(TimeUnit.MILLISECONDS)).isEqualTo(1500L);
        context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), null, context.getSourceApplicationContext(), Duration.ofMillis(2000)));
        TimeGauge readyTimeGage = registry.find("application.ready.time").timeGauge();
        assertThat(readyTimeGage).isNotNull();
        assertThat(readyTimeGage.value(TimeUnit.MILLISECONDS)).isEqualTo(2000L);
    });
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent) TimeGauge(io.micrometer.core.instrument.TimeGauge) Test(org.junit.jupiter.api.Test)

Example 4 with TimeGauge

use of io.micrometer.core.instrument.TimeGauge 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

TimeGauge (io.micrometer.core.instrument.TimeGauge)4 Test (org.junit.jupiter.api.Test)4 SpringApplication (org.springframework.boot.SpringApplication)3 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)2 ApplicationStartedEvent (org.springframework.boot.context.event.ApplicationStartedEvent)2 Issue (io.micrometer.core.Issue)1 Counter (io.micrometer.core.instrument.Counter)1 Gauge (io.micrometer.core.instrument.Gauge)1 MockClock (io.micrometer.core.instrument.MockClock)1 Tags (io.micrometer.core.instrument.Tags)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 TimeUnit (java.util.concurrent.TimeUnit)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1