Search in sources :

Example 61 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project drools by kiegroup.

the class MicrometerUtils method triggerMicrometer.

public void triggerMicrometer(BaseNode node, long evalCount, long elapsedTimeInNanos) {
    MeterRegistry meterRegistry = Metrics.globalRegistry;
    MicrometerUtils.triggerMicrometer(averageElapsedTimeCache, tags -> Timer.builder("org.drools.metric.elapsed.time.per.evaluation").tags(tags).register(meterRegistry), timer -> timer.record(Duration.ofNanos(elapsedTimeInNanos / evalCount)), node);
    MicrometerUtils.triggerMicrometer(elapsedTimeCache, tags -> Timer.builder("org.drools.metric.elapsed.time").tags(tags).register(meterRegistry), timer -> timer.record(Duration.ofNanos(elapsedTimeInNanos)), node);
    MicrometerUtils.triggerMicrometer(evaluationCountCache, tags -> Counter.builder("org.drools.metric.evaluation.count").tags(tags).register(meterRegistry), counter -> counter.increment(evalCount), node);
}
Also used : MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 62 with MeterRegistry

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

the class MicrometerBasedMetricsTest method testConnectionTimeDuration.

/**
 * Verifies that the connection time duration is recorded for the given tenant when devices get connected and
 * disconnected.
 *
 * @param registry The registry that the tests should be run against.
 */
@ParameterizedTest
@MethodSource("registries")
public void testConnectionTimeDuration(final MeterRegistry registry) {
    final MeterRegistry meterRegistry = Mockito.spy(registry);
    final Metrics metrics = new MicrometerBasedMetrics(meterRegistry, mock(Vertx.class));
    metrics.incrementConnections("TEST_TENANT");
    metrics.decrementConnections("TEST_TENANT");
    verify(meterRegistry, times(1)).timer(MicrometerBasedMetrics.METER_CONNECTIONS_AUTHENTICATED_DURATION, Tags.of(MetricsTags.getTenantTag("TEST_TENANT")));
}
Also used : Vertx(io.vertx.core.Vertx) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 63 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project pravega by pravega.

the class StatsProviderTest method testStatsProviderStartAndClose.

@Test
public void testStatsProviderStartAndClose() {
    // To improve test case isolation, create a new registry instead of using the global one.
    @Cleanup CompositeMeterRegistry localRegistry = new CompositeMeterRegistry();
    MetricsConfig appConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_STATSD_REPORTER, true).with(MetricsConfig.ENABLE_INFLUXDB_REPORTER, false).build();
    @Cleanup StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry);
    statsProvider.start();
    for (MeterRegistry registry : localRegistry.getRegistries()) {
        assertFalse(registry instanceof InfluxMeterRegistry);
        assertTrue(registry instanceof StatsdMeterRegistry);
    }
    statsProvider.close();
    assertTrue(0 == localRegistry.getRegistries().size());
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) StatsdMeterRegistry(io.micrometer.statsd.StatsdMeterRegistry) Cleanup(lombok.Cleanup) InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) StatsdMeterRegistry(io.micrometer.statsd.StatsdMeterRegistry) InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) Test(org.junit.Test)

Example 64 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project pravega by pravega.

the class PrometheusResourceTest method testScrape.

@Test
public void testScrape() throws Exception {
    MetricsConfig appConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_PROMETHEUS, true).build();
    @Cleanup CompositeMeterRegistry localRegistry = new CompositeMeterRegistry();
    @Cleanup StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry);
    statsProvider.start();
    for (MeterRegistry registry : localRegistry.getRegistries()) {
        assertTrue(registry instanceof PrometheusMeterRegistry);
    }
    assertTrue(statsProvider.prometheusResource().isPresent());
    ResourceConfig rc = ResourceConfig.forApplication(new PrometheusApplication(statsProvider));
    URI baseUri = UriBuilder.fromUri("http://localhost/").port(TestUtils.getAvailableListenPort()).build();
    @Cleanup("shutdown") HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
    Counter c = statsProvider.createStatsLogger("promtest").createCounter("promtestcounter");
    c.add(1);
    HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
    HttpRequest request = HttpRequest.newBuilder().uri(URI.create(baseUri + "prometheus")).build();
    HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
    assertTrue(response.body().lines().anyMatch(x -> Pattern.matches("promtestcounter.*1\\.0", x)));
    server.shutdown();
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) HttpRequest(java.net.http.HttpRequest) ImmutableSet(com.google.common.collect.ImmutableSet) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) SerializedClassRunner(io.pravega.test.common.SerializedClassRunner) RunWith(org.junit.runner.RunWith) Cleanup(lombok.Cleanup) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Application(javax.ws.rs.core.Application) HttpRequest(java.net.http.HttpRequest) Slf4j(lombok.extern.slf4j.Slf4j) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Assert.assertFalse(org.junit.Assert.assertFalse) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) Duration(java.time.Duration) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) GrizzlyHttpServerFactory(org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory) HttpServer(org.glassfish.grizzly.http.server.HttpServer) UriBuilder(javax.ws.rs.core.UriBuilder) HttpClient(java.net.http.HttpClient) TestUtils(io.pravega.test.common.TestUtils) URI(java.net.URI) Pattern(java.util.regex.Pattern) HttpResponse(java.net.http.HttpResponse) Cleanup(lombok.Cleanup) URI(java.net.URI) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) HttpClient(java.net.http.HttpClient) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 65 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project pravega by pravega.

the class PrometheusResourceTest method testStatsProviderNoPrometheus.

@Test
public void testStatsProviderNoPrometheus() {
    MetricsConfig appConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_STATSD_REPORTER, true).build();
    @Cleanup CompositeMeterRegistry localRegistry = new CompositeMeterRegistry();
    @Cleanup StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry);
    statsProvider.start();
    for (MeterRegistry registry : localRegistry.getRegistries()) {
        assertFalse(registry instanceof PrometheusMeterRegistry);
    }
    assertFalse(statsProvider.prometheusResource().isPresent());
    statsProvider.close();
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) Cleanup(lombok.Cleanup) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) Test(org.junit.Test)

Aggregations

MeterRegistry (io.micrometer.core.instrument.MeterRegistry)136 Test (org.junit.jupiter.api.Test)83 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)60 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)17 Timer (io.micrometer.core.instrument.Timer)15 Test (org.junit.Test)15 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)12 Duration (java.time.Duration)11 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)10 HikariDataSource (com.zaxxer.hikari.HikariDataSource)9 DataSource (javax.sql.DataSource)9 DelegatingDataSource (org.springframework.jdbc.datasource.DelegatingDataSource)9 SampleConfig (io.micrometer.core.samples.utils.SampleConfig)8 Match (io.vertx.micrometer.Match)8 FunctionCounter (io.micrometer.core.instrument.FunctionCounter)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Normal (cern.jet.random.Normal)6 MersenneTwister64 (cern.jet.random.engine.MersenneTwister64)6 RandomEngine (cern.jet.random.engine.RandomEngine)6 Gauge (io.micrometer.core.instrument.Gauge)6