Search in sources :

Example 1 with HistogramSnapshot

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

the class ElasticMeterRegistry method writeSummary.

private Stream<String> writeSummary(DistributionSummary summary, long wallTime) {
    HistogramSnapshot snap = summary.takeSnapshot();
    Stream.Builder<String> stream = Stream.builder();
    stream.add(index(summary, wallTime).field("count", summary.count()).field("sum", summary.totalAmount()).field("mean", summary.mean()).field("max", summary.max()).build());
    return stream.build();
}
Also used : OutputStream(java.io.OutputStream) Stream(java.util.stream.Stream) HistogramSnapshot(io.micrometer.core.instrument.distribution.HistogramSnapshot)

Example 2 with HistogramSnapshot

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

the class RestTemplateMetricsConfigurationTests method autoTimeRequestsCanBeConfigured.

@Test
void autoTimeRequestsCanBeConfigured() {
    this.contextRunner.withPropertyValues("management.metrics.web.client.request.autotime.enabled=true", "management.metrics.web.client.request.autotime.percentiles=0.5,0.7", "management.metrics.web.client.request.autotime.percentiles-histogram=true").run((context) -> {
        MeterRegistry registry = getInitializedMeterRegistry(context);
        Timer timer = registry.get("http.client.requests").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 : 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)

Example 3 with HistogramSnapshot

use of io.micrometer.core.instrument.distribution.HistogramSnapshot in project pravega by pravega.

the class OpStatsLoggerImpl method toOpStatsData.

@Override
public OpStatsData toOpStatsData() {
    long numFailed = fail.count();
    long numSuccess = success.count();
    HistogramSnapshot snapshot = success.takeSnapshot();
    double avgLatencyMillis = snapshot.mean();
    EnumMap<OpStatsData.Percentile, Long> percentileLongMap = new EnumMap<>(OpStatsData.Percentile.class);
    // Only add entries into percentile map when percentile values are not missing from snapshot.
    if (OpStatsData.PERCENTILE_ARRAY.length == snapshot.percentileValues().length) {
        int index = 0;
        for (OpStatsData.Percentile percent : OpStatsData.PERCENTILE_SET) {
            percentileLongMap.put(percent, (long) snapshot.percentileValues()[index++].value());
        }
    }
    return new OpStatsData(numSuccess, numFailed, avgLatencyMillis, percentileLongMap);
}
Also used : EnumMap(java.util.EnumMap) HistogramSnapshot(io.micrometer.core.instrument.distribution.HistogramSnapshot)

Example 4 with HistogramSnapshot

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

the class WebMvcMetricsAutoConfigurationTests method autoTimeRequestsCanBeConfigured.

@Test
void autoTimeRequestsCanBeConfigured() {
    this.contextRunner.withUserConfiguration(TestController.class).withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class, WebMvcAutoConfiguration.class)).withPropertyValues("management.metrics.web.server.request.autotime.enabled=true", "management.metrics.web.server.request.autotime.percentiles=0.5,0.7", "management.metrics.web.server.request.autotime.percentiles-histogram=true").run((context) -> {
        MeterRegistry registry = getInitializedMeterRegistry(context);
        Timer timer = registry.get("http.server.requests").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 : WebMvcAutoConfiguration(org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration) Timer(io.micrometer.core.instrument.Timer) MetricsAutoConfiguration(org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration) TestController(org.springframework.boot.actuate.autoconfigure.metrics.web.TestController) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) HistogramSnapshot(io.micrometer.core.instrument.distribution.HistogramSnapshot) Test(org.junit.jupiter.api.Test)

Example 5 with HistogramSnapshot

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

the class WebClientMetricsConfigurationTests method autoTimeRequestsCanBeConfigured.

@Test
void autoTimeRequestsCanBeConfigured() {
    this.contextRunner.withPropertyValues("management.metrics.web.client.request.autotime.enabled=true", "management.metrics.web.client.request.autotime.percentiles=0.5,0.7", "management.metrics.web.client.request.autotime.percentiles-histogram=true").run((context) -> {
        MeterRegistry registry = getInitializedMeterRegistry(context);
        Timer timer = registry.get("http.client.requests").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 : 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