Search in sources :

Example 1 with MicrometerMetricsOptions

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

the class MetricsExamples method setupAndAccessCustomRegistry.

public void setupAndAccessCustomRegistry() {
    Vertx vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setInfluxDbOptions(// or VertxPrometheusOptions
    new VertxInfluxDbOptions().setEnabled(true)).setRegistryName("my registry").setEnabled(true)));
    // Later on:
    MeterRegistry registry = BackendRegistries.getNow("my registry");
}
Also used : VertxInfluxDbOptions(io.vertx.micrometer.VertxInfluxDbOptions) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry)

Example 2 with MicrometerMetricsOptions

use of io.vertx.micrometer.MicrometerMetricsOptions 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 3 with MicrometerMetricsOptions

use of io.vertx.micrometer.MicrometerMetricsOptions 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 4 with MicrometerMetricsOptions

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

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

the class VertxMetricsFactoryImpl method metrics.

@Override
public VertxMetrics metrics(Vertx vertx, VertxOptions vertxOptions) {
    MetricsOptions metricsOptions = vertxOptions.getMetricsOptions();
    MicrometerMetricsOptions options;
    if (metricsOptions instanceof MicrometerMetricsOptions) {
        options = (MicrometerMetricsOptions) metricsOptions;
    } else {
        options = new MicrometerMetricsOptions(metricsOptions.toJson());
    }
    BackendRegistry backendRegistry = BackendRegistries.setupBackend(vertx, options);
    return new VertxMetricsImpl(options, backendRegistry);
}
Also used : BackendRegistry(io.vertx.micrometer.backends.BackendRegistry) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) MetricsOptions(io.vertx.core.metrics.MetricsOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions)

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