From a99d10c00254b615f1f2402cfda0f09fa3633219 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sun, 3 Jul 2016 19:59:42 -0400 Subject: [PATCH] Add basic metrics + GET /metrics route --- pom.xml | 5 +++++ src/main/java/net/frozenorb/apiv3/APIv3.java | 2 ++ src/main/java/net/frozenorb/apiv3/Main.java | 4 +++- .../net/frozenorb/apiv3/route/GETMetrics.java | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/frozenorb/apiv3/route/GETMetrics.java diff --git a/pom.xml b/pom.xml index ebdc559..2ae2003 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,11 @@ vertx-redis-client 3.3.0 + + io.vertx + vertx-dropwizard-metrics + 3.3.0 + diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index 12d1f9a..c631ac8 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -37,6 +37,7 @@ import net.frozenorb.apiv3.handler.AuthorizationHandler; import net.frozenorb.apiv3.handler.MetricsHandler; import net.frozenorb.apiv3.model.*; import net.frozenorb.apiv3.route.GETDumpsType; +import net.frozenorb.apiv3.route.GETMetrics; import net.frozenorb.apiv3.route.GETWhoAmI; import net.frozenorb.apiv3.route.accessTokens.DELETEAccessTokensId; import net.frozenorb.apiv3.route.accessTokens.GETAccessTokens; @@ -358,6 +359,7 @@ public final class APIv3 extends AbstractVerticle { http.post("/users/:userId/verifyTotp").handler(new POSTUsersIdVerifyTotp()); http.get("/dumps/:dumpType").handler(new GETDumpsType()); + http.get("/metrics").handler(new GETMetrics()); http.get("/whoami").handler(new GETWhoAmI()); int port = Integer.parseInt(config.getProperty("http.port")); diff --git a/src/main/java/net/frozenorb/apiv3/Main.java b/src/main/java/net/frozenorb/apiv3/Main.java index a427611..28131bb 100644 --- a/src/main/java/net/frozenorb/apiv3/Main.java +++ b/src/main/java/net/frozenorb/apiv3/Main.java @@ -1,6 +1,8 @@ package net.frozenorb.apiv3; import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; +import io.vertx.ext.dropwizard.DropwizardMetricsOptions; final class Main { @@ -8,7 +10,7 @@ final class Main { System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "error"); System.setProperty("org.slf4j.simpleLogger.showThreadName", "false"); System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory"); - Vertx.vertx().deployVerticle(new APIv3()); + Vertx.vertx(new VertxOptions().setMetricsOptions(new DropwizardMetricsOptions().setEnabled(true))).deployVerticle(new APIv3()); } } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/route/GETMetrics.java b/src/main/java/net/frozenorb/apiv3/route/GETMetrics.java new file mode 100644 index 0000000..8bbbacf --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/route/GETMetrics.java @@ -0,0 +1,18 @@ +package net.frozenorb.apiv3.route; + +import io.vertx.core.Handler; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.dropwizard.MetricsService; +import io.vertx.ext.web.RoutingContext; +import net.frozenorb.apiv3.APIv3; + +public final class GETMetrics implements Handler { + + public void handle(RoutingContext ctx) { + MetricsService metricsService = MetricsService.create(APIv3.getVertxInstance()); + JsonObject metrics = metricsService.getMetricsSnapshot(APIv3.getVertxInstance()); + + APIv3.respondJson(ctx, 200, metrics); + } + +} \ No newline at end of file