Add more metrics
This commit is contained in:
parent
26db4bb255
commit
76e2b60250
@ -17,6 +17,7 @@ public class AuditLog {
|
||||
}
|
||||
|
||||
public static void log(User performedBy, String performedByIp, Actor actor, AuditLogActionType actionType, Map<String, Object> actionData) {
|
||||
APIv3.getStatsD().incrementCounter("apiv3.auditLog.insertions");
|
||||
APIv3.getDatastore().save(new AuditLogEntry(performedBy, performedByIp, actor, actionType, actionData));
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ public final class AuthorizationFilter implements Filter {
|
||||
if (!actor.isAuthorized()) {
|
||||
APIv3.getStatsD().incrementCounter("apiv3.http.unauthorized");
|
||||
res.header("WWW-Authenticate", "Basic realm=\"MineHQ\"");
|
||||
Spark.halt(401, APIv3.getGson().toJson(ErrorUtils.error("Unauthorized access: Please authenticate as either a server, the website, or an authorized user. You're currently authorized as " + actor.getName())));
|
||||
Spark.halt(401, APIv3.getGson().toJson(ErrorUtils.error("Unauthorized access: Please authorize as an approved actor. You're currently authorized as " + actor.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.frozenorb.apiv3.filters;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.frozenorb.apiv3.actors.Actor;
|
||||
import spark.Filter;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
@ -13,11 +14,8 @@ public final class LoggingFilter implements Filter {
|
||||
@Getter @Setter private static boolean debug = false;
|
||||
|
||||
public void handle(Request req, Response res) {
|
||||
if (debug) {
|
||||
log.info(req.requestMethod().toUpperCase() + " " + req.url() + "\n" + res.body());
|
||||
} else {
|
||||
log.info(req.requestMethod().toUpperCase() + " " + req.url());
|
||||
}
|
||||
Actor actor = req.attribute("actor");
|
||||
log.info("(" + actor.getName() + " - " + actor.getType() + ") " + req.requestMethod().toUpperCase() + " " + req.pathInfo() + (debug ? "\n" + res.body() : ""));
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package net.frozenorb.apiv3.routes;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.timgroup.statsd.Event;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.models.Grant;
|
||||
import net.frozenorb.apiv3.models.Punishment;
|
||||
|
@ -7,6 +7,7 @@ import com.cribbstechnologies.clients.mandrill.model.MandrillRecipient;
|
||||
import com.cribbstechnologies.clients.mandrill.request.MandrillMessagesRequest;
|
||||
import com.twilio.sdk.TwilioRestException;
|
||||
import com.twilio.sdk.resource.factory.MessageFactory;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.models.NotificationTemplate;
|
||||
import net.frozenorb.apiv3.utils.MandrillUtils;
|
||||
import net.frozenorb.apiv3.utils.TwillioUtils;
|
||||
@ -46,7 +47,9 @@ public final class Notification {
|
||||
MandrillMessageRequest request = new MandrillMessageRequest();
|
||||
request.setMessage(message);
|
||||
mandrillMessagesRequest.sendMessage(request);
|
||||
APIv3.getStatsD().incrementCounter("apiv3.notification.email.success");
|
||||
} catch (RequestFailedException ex) {
|
||||
APIv3.getStatsD().incrementCounter("apiv3.notification.email.failure");
|
||||
throw new IOException("Failed to send notification to user", ex);
|
||||
}
|
||||
}
|
||||
@ -60,7 +63,9 @@ public final class Notification {
|
||||
|
||||
try {
|
||||
twillioMessageFactory.create(params);
|
||||
APIv3.getStatsD().incrementCounter("apiv3.notification.text.success");
|
||||
} catch (TwilioRestException ex) {
|
||||
APIv3.getStatsD().incrementCounter("apiv3.notification.text.failure");
|
||||
throw new IOException("Failed to send notification to user", ex);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.frozenorb.apiv3.utils;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
@ -29,8 +30,10 @@ public class MojangUtils {
|
||||
throw new RuntimeException("Hit Mojang API rate limit");
|
||||
}
|
||||
|
||||
APIv3.getStatsD().incrementCounter("apiv3.mojang.sessionServer.success");
|
||||
return name;
|
||||
} catch (Exception ex) {
|
||||
APIv3.getStatsD().incrementCounter("apiv3.mojang.sessionServer.failure");
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,13 @@ public class TOTPUtils {
|
||||
}
|
||||
|
||||
public static boolean authorizeUser(User user, int code) {
|
||||
return googleAuthenticator.authorize(user.getTotpSecret(), code);
|
||||
boolean authorized = googleAuthenticator.authorize(user.getTotpSecret(), code);
|
||||
|
||||
if (!authorized) {
|
||||
APIv3.getStatsD().incrementCounter("apiv3.totp.failure");
|
||||
}
|
||||
|
||||
return authorized;
|
||||
}
|
||||
|
||||
public static String getQRCodeURL(User user, GoogleAuthenticatorKey key) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.frozenorb.apiv3.utils;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -8,7 +9,13 @@ import java.util.UUID;
|
||||
public class UUIDUtils {
|
||||
|
||||
public static boolean isAcceptableUUID(UUID uuid) {
|
||||
return uuid.version() == 4;
|
||||
boolean acceptable = uuid.version() == 4;
|
||||
|
||||
if (!acceptable) {
|
||||
APIv3.getStatsD().incrementCounter("apiv3.uuid.invalid");
|
||||
}
|
||||
|
||||
return acceptable;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user