Search in sources :

Example 1 with VertxPrometheusOptions

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

the class MetricsExamples method setupPrometheusBoundRouter.

public void setupPrometheusBoundRouter() {
    Vertx vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)).setEnabled(true)));
    // Later on, creating a router
    Router router = Router.router(vertx);
    router.route("/metrics").handler(routingContext -> {
        PrometheusMeterRegistry prometheusRegistry = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
        if (prometheusRegistry != null) {
            String response = prometheusRegistry.scrape();
            routingContext.response().end(response);
        } else {
            routingContext.fail(500);
        }
    });
    vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Router(io.vertx.ext.web.Router) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions)

Example 2 with VertxPrometheusOptions

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

the class PrometheusMetricsITest method shouldExposeEventBusMetrics.

@Test
public void shouldExposeEventBusMetrics(TestContext context) {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true).setStartEmbeddedServer(true).setEmbeddedServerOptions(new HttpServerOptions().setPort(9090))).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 metrics on HTTP endpoint for eventbus metrics
    Async async = context.async();
    HttpClientRequest req = vertx.createHttpClient().get(9090, "localhost", "/metrics").handler(res -> {
        context.assertEquals(200, res.statusCode());
        res.bodyHandler(body -> {
            String str = body.toString();
            context.verify(v -> assertThat(str).contains("vertx_eventbus_published_total{address=\"test-eb\",side=\"local\",} 1.0", "vertx_eventbus_received_total{address=\"test-eb\",side=\"local\",} 1.0", "vertx_eventbus_handlers{address=\"test-eb\",} 1.0", "vertx_eventbus_delivered_total{address=\"test-eb\",side=\"local\",} 1.0", "vertx_eventbus_processingTime_seconds_count{address=\"test-eb\",} 1.0"));
            async.complete();
        });
    });
    req.end();
    async.awaitSuccess(10000);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) 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 3 with VertxPrometheusOptions

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

the class MetricsServiceImplTest method setUp.

@Before
public void setUp(TestContext ctx) {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)).setRegistryName(registryName).setEnabled(true))).exceptionHandler(ctx.exceptionHandler());
    // Setup server
    Async serverReady = ctx.async();
    httpServer = vertx.createHttpServer();
    httpServer.requestHandler(req -> {
        // Timer as artificial processing time
        vertx.setTimer(30L, handler -> req.response().setChunked(true).putHeader("Content-Type", "text/plain").write(SERVER_RESPONSE).end());
    }).listen(9195, "127.0.0.1", r -> {
        if (r.failed()) {
            ctx.fail(r.cause());
        } else {
            serverReady.complete();
        }
    });
    serverReady.awaitSuccess();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) HttpServer(io.vertx.core.http.HttpServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) RunWith(org.junit.runner.RunWith) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) UUID(java.util.UUID) MetricsService(io.vertx.micrometer.MetricsService) JsonArray(io.vertx.core.json.JsonArray) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) List(java.util.List) After(org.junit.After) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) HttpClient(io.vertx.core.http.HttpClient) Before(org.junit.Before) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Async(io.vertx.ext.unit.Async) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) Before(org.junit.Before)

Example 4 with VertxPrometheusOptions

use of io.vertx.micrometer.VertxPrometheusOptions 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 5 with VertxPrometheusOptions

use of io.vertx.micrometer.VertxPrometheusOptions 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)

Aggregations

VertxOptions (io.vertx.core.VertxOptions)6 MicrometerMetricsOptions (io.vertx.micrometer.MicrometerMetricsOptions)6 VertxPrometheusOptions (io.vertx.micrometer.VertxPrometheusOptions)6 Async (io.vertx.ext.unit.Async)5 Test (org.junit.Test)5 HttpServerOptions (io.vertx.core.http.HttpServerOptions)3 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)2 Vertx (io.vertx.core.Vertx)2 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 Router (io.vertx.ext.web.Router)2 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 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 MetricsService (io.vertx.micrometer.MetricsService)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1