Readd very basic metrics

This commit is contained in:
Colin McDonald 2016-06-25 18:02:07 -04:00
parent 70d26256bd
commit 3381d74a8b
2 changed files with 42 additions and 0 deletions

View File

@ -35,6 +35,7 @@ import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.handler.ActorAttributeHandler;
import net.frozenorb.apiv3.handler.AuthorizationHandler;
import net.frozenorb.apiv3.handler.MetricsHandler;
import net.frozenorb.apiv3.route.GETDumpsType;
import net.frozenorb.apiv3.route.GETWhoAmI;
import net.frozenorb.apiv3.route.auditLog.GETAuditLog;
@ -225,6 +226,7 @@ public final class APIv3 extends AbstractVerticle {
http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(5)));
http.route().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create());
http.route().handler(new ActorAttributeHandler());
http.route().handler(new MetricsHandler());
http.route().handler(new AuthorizationHandler());
// TODO: The commented out routes

View File

@ -0,0 +1,40 @@
package net.frozenorb.apiv3.handler;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import io.vertx.redis.RedisClient;
import io.vertx.redis.RedisOptions;
import net.frozenorb.apiv3.APIv3;
public final class MetricsHandler implements Handler<RoutingContext> {
private static final RedisClient redisClient = RedisClient.create(APIv3.getVertxInstance(),
new RedisOptions()
.setAddress(APIv3.getConfig().getProperty("redis.address"))
.setPort(Integer.parseInt(APIv3.getConfig().getProperty("redis.port")))
);
@Override
public void handle(RoutingContext ctx) {
redisClient.incr("apiv3:requests:total", (totalUpdateResult) -> {
if (totalUpdateResult.failed()) {
totalUpdateResult.cause().printStackTrace();
} else {
redisClient.incr("apiv3:requests:method:" + ctx.request().method(), (methodUpdateResult) -> {
if (methodUpdateResult.failed()) {
methodUpdateResult.cause().printStackTrace();
} else {
redisClient.incr("apiv3:requests:actor:" + ctx.get("actor").getClass().getSimpleName(), (actorUpdateResult) -> {
if (actorUpdateResult.failed()) {
actorUpdateResult.cause().printStackTrace();
}
});
}
});
}
});
ctx.next();
}
}