Search in sources :

Example 6 with HistogramSnapshot

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

the class WebMvcMetricsFilterAutoTimedTests method metricsCanBeAutoTimed.

@Test
void metricsCanBeAutoTimed() throws Exception {
    this.mvc.perform(get("/api/10")).andExpect(status().isOk());
    Timer timer = this.registry.get("http.server.requests").tags("status", "200").timer();
    assertThat(timer.count()).isEqualTo(1L);
    HistogramSnapshot snapshot = timer.takeSnapshot();
    assertThat(snapshot.percentileValues()).hasSize(2);
    assertThat(snapshot.percentileValues()[0].percentile()).isEqualTo(0.5);
    assertThat(snapshot.percentileValues()[1].percentile()).isEqualTo(0.95);
}
Also used : Timer(io.micrometer.core.instrument.Timer) HistogramSnapshot(io.micrometer.core.instrument.distribution.HistogramSnapshot) Test(org.junit.jupiter.api.Test)

Example 7 with HistogramSnapshot

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

the class RepositoryMetricsAutoConfigurationTests method autoTimeRequestsCanBeConfigured.

@Test
void autoTimeRequestsCanBeConfigured() {
    this.contextRunner.withPropertyValues("management.metrics.data.repository.autotime.enabled=true", "management.metrics.data.repository.autotime.percentiles=0.5,0.7").run((context) -> {
        MeterRegistry registry = getInitializedMeterRegistry(context, ExampleRepository.class);
        Timer timer = registry.get("spring.data.repository.invocations").timer();
        HistogramSnapshot snapshot = timer.takeSnapshot();
        assertThat(snapshot.percentileValues()).hasSize(2);
        assertThat(snapshot.percentileValues()[0].percentile()).isEqualTo(0.5);
        assertThat(snapshot.percentileValues()[1].percentile()).isEqualTo(0.7);
    });
}
Also used : AutoTimer(org.springframework.boot.actuate.metrics.AutoTimer) Timer(io.micrometer.core.instrument.Timer) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) HistogramSnapshot(io.micrometer.core.instrument.distribution.HistogramSnapshot) Test(org.junit.jupiter.api.Test)

Aggregations

HistogramSnapshot (io.micrometer.core.instrument.distribution.HistogramSnapshot)7 Timer (io.micrometer.core.instrument.Timer)5 Test (org.junit.jupiter.api.Test)5 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)4 OutputStream (java.io.OutputStream)1 EnumMap (java.util.EnumMap)1 Stream (java.util.stream.Stream)1 MetricsAutoConfiguration (org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration)1 TestController (org.springframework.boot.actuate.autoconfigure.metrics.web.TestController)1 AutoTimer (org.springframework.boot.actuate.metrics.AutoTimer)1 WebMvcAutoConfiguration (org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration)1