Search in sources :

Example 1 with MetricsService

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);
    }
}
Also used : MetricsService(io.vertx.ext.dropwizard.MetricsService) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with MetricsService

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");
}
Also used : Random(java.util.Random) MetricsService(io.vertx.ext.dropwizard.MetricsService) HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.web.handler.sockjs.PermittedOptions)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)2 MetricsService (io.vertx.ext.dropwizard.MetricsService)2 HttpServer (io.vertx.core.http.HttpServer)1 Router (io.vertx.ext.web.Router)1 BridgeOptions (io.vertx.ext.web.handler.sockjs.BridgeOptions)1 PermittedOptions (io.vertx.ext.web.handler.sockjs.PermittedOptions)1 Random (java.util.Random)1