use of io.vertx.ext.dropwizard.MetricsService in project chili-core by codingchili.
the class SystemContext method initialize.
private void initialize() {
executor = vertx.createSharedWorkerExecutor("systemcontext", system().getWorkerPoolSize());
vertx.exceptionHandler(throwable -> logger.onError(throwable));
if (!initialized.get()) {
MetricsService metrics = MetricsService.create(vertx);
periodic(this::getMetricTimer, CoreStrings.LOG_METRICS, handler -> {
if (system().isMetrics()) {
JsonObject json = metrics.getMetricsSnapshot(vertx);
this.onMetricsSnapshot(json);
}
});
StartupListener.publish(this);
initialized.set(true);
}
}
use of io.vertx.ext.dropwizard.MetricsService in project vertx-examples by vert-x3.
the class Dashboard method start.
@Override
public void start() {
MetricsService service = MetricsService.create(vertx);
Router router = Router.router(vertx);
// Allow outbound traffic to the news-feed address
BridgeOptions options = new BridgeOptions().addOutboundPermitted(new PermittedOptions().setAddress("metrics"));
router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options));
// Serve the static resources
router.route().handler(StaticHandler.create());
HttpServer httpServer = vertx.createHttpServer();
httpServer.requestHandler(router::accept).listen(8080);
// Send a metrics events every second
vertx.setPeriodic(1000, t -> {
JsonObject metrics = service.getMetricsSnapshot(vertx.eventBus());
vertx.eventBus().publish("metrics", metrics);
});
// Send some messages
Random random = new Random();
vertx.eventBus().consumer("whatever", msg -> {
vertx.setTimer(10 + random.nextInt(50), id -> {
vertx.eventBus().send("whatever", "hello");
});
});
vertx.eventBus().send("whatever", "hello");
}
Aggregations