Search in sources :

Example 1 with InfluxMeterRegistry

use of io.micrometer.influx.InfluxMeterRegistry in project pravega by pravega.

the class StatsProviderImpl method start.

@Synchronized
@Override
public void start() {
    log.info("Metrics prefix: {}", conf.getMetricsPrefix());
    if (conf.isEnableStatsDReporter()) {
        metrics.add(new StatsdMeterRegistry(RegistryConfigUtil.createStatsDConfig(conf), Clock.SYSTEM));
    }
    if (conf.isEnableInfluxDBReporter()) {
        metrics.add(new InfluxMeterRegistry(RegistryConfigUtil.createInfluxConfig(conf), Clock.SYSTEM));
    }
    if (conf.isEnablePrometheus()) {
        this.prometheusRegistry = new PrometheusMeterRegistry(RegistryConfigUtil.createPrometheusConfig(conf));
        metrics.add(prometheusRegistry);
    }
    Preconditions.checkArgument(metrics.getRegistries().size() != 0, "No meter register bound hence no storage for metrics!");
    init();
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) StatsdMeterRegistry(io.micrometer.statsd.StatsdMeterRegistry) InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) Synchronized(lombok.Synchronized)

Example 2 with InfluxMeterRegistry

use of io.micrometer.influx.InfluxMeterRegistry 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 3 with InfluxMeterRegistry

use of io.micrometer.influx.InfluxMeterRegistry in project vertx-micrometer-metrics by vert-x3.

the class CustomMicrometerMetricsITest method shouldReportWithCompositeRegistry.

@Test
public void shouldReportWithCompositeRegistry(TestContext context) throws Exception {
    // Mock an influxdb server
    Async asyncInflux = context.async();
    InfluxDbTestHelper.simulateInfluxServer(vertxForSimulatedServer, context, 8087, body -> {
        try {
            context.verify(w -> assertThat(body).contains("vertx_eventbus_handlers,address=test-eb,metric_type=gauge value=1"));
        } finally {
            asyncInflux.complete();
        }
    });
    CompositeMeterRegistry myRegistry = new CompositeMeterRegistry();
    myRegistry.add(new JmxMeterRegistry(s -> null, Clock.SYSTEM));
    myRegistry.add(new InfluxMeterRegistry(new InfluxConfig() {

        @Override
        public String get(String s) {
            return null;
        }

        @Override
        public Duration step() {
            return Duration.ofSeconds(1);
        }

        @Override
        public String uri() {
            return "http://localhost:8087";
        }

        @Override
        public boolean autoCreateDb() {
            return false;
        }
    }, Clock.SYSTEM));
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setMicrometerRegistry(myRegistry).setRegistryName(REGITRY_NAME).addDisabledMetricsCategory(MetricsDomain.HTTP_SERVER).addDisabledMetricsCategory(MetricsDomain.NAMED_POOLS).addLabels(Label.EB_ADDRESS).setEnabled(true)));
    // Send something on the eventbus and wait til it's received
    Async asyncEB = context.async();
    vertx.eventBus().consumer("test-eb", msg -> asyncEB.complete());
    vertx.eventBus().publish("test-eb", "test message");
    asyncEB.await(2000);
    // Read MBean
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    assertThat(mbs.getDomains()).contains("metrics");
    Number result = (Number) mbs.getAttribute(new ObjectName("metrics", "name", "vertxEventbusHandlers.address.test-eb"), "Value");
    assertThat(result).isEqualTo(1d);
    // Await influx
    asyncInflux.awaitSuccess();
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) After(org.junit.After) MBeanServer(javax.management.MBeanServer) Duration(java.time.Duration) ManagementFactory(java.lang.management.ManagementFactory) Clock(io.micrometer.core.instrument.Clock) InfluxConfig(io.micrometer.influx.InfluxConfig) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) JmxMeterRegistry(io.micrometer.jmx.JmxMeterRegistry) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MetricsDomain(io.vertx.micrometer.MetricsDomain) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) ObjectName(javax.management.ObjectName) InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Label(io.vertx.micrometer.Label) PrometheusConfig(io.micrometer.prometheus.PrometheusConfig) Async(io.vertx.ext.unit.Async) JmxMeterRegistry(io.micrometer.jmx.JmxMeterRegistry) InfluxConfig(io.micrometer.influx.InfluxConfig) InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 4 with InfluxMeterRegistry

use of io.micrometer.influx.InfluxMeterRegistry in project pravega by pravega.

the class StatsProviderTest method testStatsProviderStartWithoutExporting.

@Test
public void testStatsProviderStartWithoutExporting() {
    MetricsConfig appConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_STATSD_REPORTER, true).with(MetricsConfig.ENABLE_INFLUXDB_REPORTER, true).build();
    @Cleanup CompositeMeterRegistry localRegistry = new CompositeMeterRegistry();
    @Cleanup StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry);
    statsProvider.startWithoutExporting();
    for (MeterRegistry registry : localRegistry.getRegistries()) {
        assertTrue(registry instanceof SimpleMeterRegistry);
        assertFalse(registry instanceof InfluxMeterRegistry);
        assertFalse(registry instanceof StatsdMeterRegistry);
    }
    statsProvider.close();
    assertTrue(0 == localRegistry.getRegistries().size());
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) 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 5 with InfluxMeterRegistry

use of io.micrometer.influx.InfluxMeterRegistry in project spring-boot by spring-projects.

the class InfluxMetricsExportAutoConfigurationTests method stopsMeterRegistryWhenContextIsClosed.

@Test
void stopsMeterRegistryWhenContextIsClosed() {
    this.contextRunner.withUserConfiguration(BaseConfiguration.class).run((context) -> {
        InfluxMeterRegistry registry = context.getBean(InfluxMeterRegistry.class);
        assertThat(registry.isClosed()).isFalse();
        context.close();
        assertThat(registry.isClosed()).isTrue();
    });
}
Also used : InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

InfluxMeterRegistry (io.micrometer.influx.InfluxMeterRegistry)5 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)3 StatsdMeterRegistry (io.micrometer.statsd.StatsdMeterRegistry)3 Test (org.junit.Test)3 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)2 Cleanup (lombok.Cleanup)2 Clock (io.micrometer.core.instrument.Clock)1 InfluxConfig (io.micrometer.influx.InfluxConfig)1 JmxMeterRegistry (io.micrometer.jmx.JmxMeterRegistry)1 PrometheusConfig (io.micrometer.prometheus.PrometheusConfig)1 Vertx (io.vertx.core.Vertx)1 VertxOptions (io.vertx.core.VertxOptions)1 HttpServerOptions (io.vertx.core.http.HttpServerOptions)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 Label (io.vertx.micrometer.Label)1 MetricsDomain (io.vertx.micrometer.MetricsDomain)1