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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations