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