diff --git a/pom.xml b/pom.xml
index c00290d..58fa9ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,13 +80,8 @@
com.librato.metrics
- metrics-librato
- 4.1.2.5
-
-
- io.dropwizard.metrics
- metrics-core
- 3.1.2
+ librato-java
+ 1.0.13
com.bugsnag
diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java
index bd544ca..b33cb81 100644
--- a/src/main/java/net/frozenorb/apiv3/APIv3.java
+++ b/src/main/java/net/frozenorb/apiv3/APIv3.java
@@ -1,20 +1,18 @@
package net.frozenorb.apiv3;
import com.bugsnag.Client;
-import com.codahale.metrics.Gauge;
-import com.codahale.metrics.MetricRegistry;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import com.librato.metrics.LibratoReporter;
+import com.librato.metrics.*;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.filters.*;
import net.frozenorb.apiv3.routes.GETDump;
import net.frozenorb.apiv3.routes.GETWhoAmI;
import net.frozenorb.apiv3.routes.NotFound;
import net.frozenorb.apiv3.routes.POSTMetrics;
-import net.frozenorb.apiv3.routes.servers.POSTServerHeartbeat;
import net.frozenorb.apiv3.routes.announcements.GETAnnouncements;
import net.frozenorb.apiv3.routes.auditLog.GETAuditLog;
import net.frozenorb.apiv3.routes.chatFilterList.GETChatFilterList;
@@ -48,16 +46,19 @@ import redis.clients.jedis.JedisPool;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import static spark.Spark.*;
+@Slf4j
public final class APIv3 {
@Getter private static Datastore datastore;
@Getter private static Properties config = new Properties();
@Getter private static JedisPool redisPool;
- @Getter private static MetricRegistry metrics = new MetricRegistry();
+ @Getter private static HttpPoster libratoPoster;
@Getter private static Client bugsnagClient;
@Getter private static final Gson gson = new GsonBuilder()
.registerTypeAdapter(ObjectId.class, new ObjectIdTypeAdapter())
@@ -70,9 +71,11 @@ public final class APIv3 {
setupDatabase();
setupRedis();
- setupMetrics();
+ setupLibrato();
setupBugsnag();
setupHttp();
+
+ log.info("APIv3 booted.");
}
private void setupConfig() {
@@ -113,23 +116,36 @@ public final class APIv3 {
);
}
- private void setupMetrics() {
- Gauge memoryUsageGauge = () -> Runtime.getRuntime().totalMemory() / (1024 * 1024);
- Gauge memoryMaxGauge = () -> Runtime.getRuntime().maxMemory() / (1024 * 1024);
+ private void setupLibrato() {
+ try {
+ libratoPoster = new DefaultHttpPoster(
+ "https://metrics-api.librato.com/v1/metrics",
+ config.getProperty("librato.email"),
+ config.getProperty("librato.apiKey")
+ );
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
- metrics.register(MetricRegistry.name("apiv3", "memory", "usage"), memoryUsageGauge);
- metrics.register(MetricRegistry.name("apiv3", "memory", "max"), memoryMaxGauge);
+ new Timer("Librato Post Task").scheduleAtFixedRate(new TimerTask() {
- LibratoReporter.enable(
- LibratoReporter.builder(
- metrics,
- config.getProperty("librato.email"),
- config.getProperty("librato.apiKey"),
- config.getProperty("general.id")
- ),
- 1,
- TimeUnit.MINUTES
- );
+ @Override
+ public void run() {
+ LibratoBatch batch = new LibratoBatch(300, Sanitizer.NO_OP, 10, TimeUnit.SECONDS, "qLib", libratoPoster);
+
+ batch.addGaugeMeasurement("apiv3.memory.usage", Runtime.getRuntime().totalMemory() / (1024 * 1024));
+ batch.addGaugeMeasurement("apiv3.memory.max", Runtime.getRuntime().maxMemory() / (1024 * 1024));
+
+ BatchResult result = batch.post(config.getProperty("general.id"), System.currentTimeMillis() / 1000L);
+
+ if (!result.success()) {
+ for (PostResult post : result.getFailedPosts()) {
+ log.warn("Could not POST to Librato: " + post);
+ }
+ }
+ }
+
+ }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MINUTES.toMillis(1));
}
private void setupBugsnag() {
diff --git a/src/main/java/net/frozenorb/apiv3/actors/BungeeCordActor.java b/src/main/java/net/frozenorb/apiv3/actors/BungeeCordActor.java
index fd77cfa..aa4734d 100644
--- a/src/main/java/net/frozenorb/apiv3/actors/BungeeCordActor.java
+++ b/src/main/java/net/frozenorb/apiv3/actors/BungeeCordActor.java
@@ -1,7 +1,5 @@
package net.frozenorb.apiv3.actors;
-import net.frozenorb.apiv3.models.Server;
-
public final class BungeeCordActor implements Actor {
public boolean isAuthorized() {
diff --git a/src/main/java/net/frozenorb/apiv3/filters/MetricsAfterFilter.java b/src/main/java/net/frozenorb/apiv3/filters/MetricsAfterFilter.java
index 11fcd99..7020f4e 100644
--- a/src/main/java/net/frozenorb/apiv3/filters/MetricsAfterFilter.java
+++ b/src/main/java/net/frozenorb/apiv3/filters/MetricsAfterFilter.java
@@ -1,25 +1,19 @@
package net.frozenorb.apiv3.filters;
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
-import net.frozenorb.apiv3.APIv3;
import spark.Filter;
import spark.Request;
import spark.Response;
-import java.util.concurrent.TimeUnit;
-
public final class MetricsAfterFilter implements Filter {
- private Histogram responseLengthMetric = APIv3.getMetrics().histogram(MetricRegistry.name("apiv3", "http", "responseLength"));
- private Timer responseTimesMetric = APIv3.getMetrics().timer(MetricRegistry.name("apiv3", "http", "responseTimes"));
+ /*private Histogram responseLengthMetric = APIv3.getMetrics().histogram(MetricRegistry.name("apiv3", "http", "responseLength"));
+ private Timer responseTimesMetric = APIv3.getMetrics().timer(MetricRegistry.name("apiv3", "http", "responseTimes"));*/
public void handle(Request req, Response res) {
- responseLengthMetric.update(req.contentLength());
+ /*responseLengthMetric.update(req.contentLength());
long started = req.attribute("requestStarted");
- responseTimesMetric.update(System.currentTimeMillis() - started, TimeUnit.MILLISECONDS);
+ responseTimesMetric.update(System.currentTimeMillis() - started, TimeUnit.MILLISECONDS);*/
}
}
\ No newline at end of file
diff --git a/src/main/java/net/frozenorb/apiv3/routes/POSTMetrics.java b/src/main/java/net/frozenorb/apiv3/routes/POSTMetrics.java
index d7c9bb3..9ff93d4 100644
--- a/src/main/java/net/frozenorb/apiv3/routes/POSTMetrics.java
+++ b/src/main/java/net/frozenorb/apiv3/routes/POSTMetrics.java
@@ -1,10 +1,6 @@
package net.frozenorb.apiv3.routes;
import com.google.common.collect.ImmutableMap;
-import net.frozenorb.apiv3.actors.Actor;
-import net.frozenorb.apiv3.actors.ActorType;
-import net.frozenorb.apiv3.models.Server;
-import net.frozenorb.apiv3.utils.ErrorUtils;
import spark.Request;
import spark.Response;
import spark.Route;
diff --git a/src/main/java/net/frozenorb/apiv3/unsorted/LoggingExceptionHandler.java b/src/main/java/net/frozenorb/apiv3/unsorted/LoggingExceptionHandler.java
index 8583aaf..7405a19 100644
--- a/src/main/java/net/frozenorb/apiv3/unsorted/LoggingExceptionHandler.java
+++ b/src/main/java/net/frozenorb/apiv3/unsorted/LoggingExceptionHandler.java
@@ -1,6 +1,5 @@
package net.frozenorb.apiv3.unsorted;
-import com.codahale.metrics.Timer;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.utils.ErrorUtils;
@@ -13,8 +12,8 @@ import spark.Response;
public final class LoggingExceptionHandler implements ExceptionHandler {
public void handle(Exception ex, Request req, Response res) {
- Timer.Context timerMetric = req.attribute("timerMetric");
- timerMetric.stop();
+ //Timer.Context timerMetric = req.attribute("timerMetric");
+ //timerMetric.stop();
String code = new ObjectId().toHexString();