Search in sources :

Example 6 with MicrometerMetricsOptions

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

the class JmxMetricsITest method shouldReportJmx.

@Test
public void shouldReportJmx(TestContext context) throws Exception {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setJmxMetricsOptions(new VertxJmxMetricsOptions().setEnabled(true).setStep(1)).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);
}
Also used : Async(io.vertx.ext.unit.Async) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) VertxJmxMetricsOptions(io.vertx.micrometer.VertxJmxMetricsOptions) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 7 with MicrometerMetricsOptions

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

the class PrometheusMetricsITest method shouldStartEmbeddedServer.

@Test
public void shouldStartEmbeddedServer(TestContext context) {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true).setStartEmbeddedServer(true).setEmbeddedServerOptions(new HttpServerOptions().setPort(9090))).setEnabled(true)));
    Async async = context.async();
    tryConnect(vertx, context, 9090, "localhost", "/metrics", body -> {
        context.verify(v -> assertThat(body).contains("vertx_http_server_connections{local=\"0.0.0.0:9090\",remote=\"_\",} 1.0"));
        async.complete();
    }, 0);
    async.awaitSuccess(10000);
}
Also used : VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Async(io.vertx.ext.unit.Async) HttpServerOptions(io.vertx.core.http.HttpServerOptions) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) Test(org.junit.Test)

Example 8 with MicrometerMetricsOptions

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

the class PrometheusMetricsITest method shouldBindExistingServer.

@Test
public void shouldBindExistingServer(TestContext context) {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)).setEnabled(true)));
    Router router = Router.router(vertx);
    router.route("/custom").handler(routingContext -> {
        PrometheusMeterRegistry prometheusRegistry = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
        String response = prometheusRegistry.scrape();
        routingContext.response().end(response);
    });
    vertx.createHttpServer().requestHandler(router::accept).listen(8081);
    Async async = context.async();
    HttpClientRequest req = vertx.createHttpClient().get(8081, "localhost", "/custom").handler(res -> {
        context.assertEquals(200, res.statusCode());
        res.bodyHandler(body -> {
            context.verify(v -> assertThat(body.toString()).contains("vertx_http_"));
            async.complete();
        });
    });
    req.end();
    async.awaitSuccess(10000);
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) HttpClientRequest(io.vertx.core.http.HttpClientRequest) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Async(io.vertx.ext.unit.Async) Router(io.vertx.ext.web.Router) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) Test(org.junit.Test)

Example 9 with MicrometerMetricsOptions

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

the class PrometheusMetricsITest method shouldExcludeCategory.

@Test
public void shouldExcludeCategory(TestContext context) {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true).setStartEmbeddedServer(true).setEmbeddedServerOptions(new HttpServerOptions().setPort(9090))).addDisabledMetricsCategory(MetricsDomain.HTTP_SERVER).setEnabled(true)));
    Async async = context.async();
    tryConnect(vertx, context, 9090, "localhost", "/metrics", body -> {
        context.verify(v -> assertThat(body).contains("vertx_http_client_connections{local=\"?\",remote=\"localhost:9090\",} 1.0").doesNotContain("vertx_http_server_connections{local=\"0.0.0.0:9090\",remote=\"_\",} 1.0"));
        async.complete();
    }, 0);
    async.awaitSuccess(10000);
}
Also used : VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Async(io.vertx.ext.unit.Async) HttpServerOptions(io.vertx.core.http.HttpServerOptions) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) Test(org.junit.Test)

Aggregations

MicrometerMetricsOptions (io.vertx.micrometer.MicrometerMetricsOptions)9 VertxOptions (io.vertx.core.VertxOptions)8 Async (io.vertx.ext.unit.Async)6 VertxPrometheusOptions (io.vertx.micrometer.VertxPrometheusOptions)6 Test (org.junit.Test)6 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)3 Vertx (io.vertx.core.Vertx)3 HttpServerOptions (io.vertx.core.http.HttpServerOptions)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 Router (io.vertx.ext.web.Router)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpServer (io.vertx.core.http.HttpServer)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 MetricsOptions (io.vertx.core.metrics.MetricsOptions)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 MetricsService (io.vertx.micrometer.MetricsService)1 VertxInfluxDbOptions (io.vertx.micrometer.VertxInfluxDbOptions)1