diff --git a/config.dev.yml b/config.dev.yml
index eadcda9c..a0d6d0e9 100644
--- a/config.dev.yml
+++ b/config.dev.yml
@@ -28,6 +28,14 @@ app:
smtpTls: false
smtpUserName: user
smtpPassword: pass
+
+ # Graphite Metric settings
+ # Allows those who use Graphite to have CommaFeed send metrics for graphing (time in seconds)
+ graphiteEnabled: false
+ graphitePrefix: "test.commafeed"
+ graphiteHost: "localhost"
+ graphitePort: 2003
+ graphiteInterval: 60
# wether this commafeed instance has a lot of feeds to refresh
# leave this to false in almost all cases
diff --git a/config.yml.example b/config.yml.example
index 5f6d1674..65409954 100644
--- a/config.yml.example
+++ b/config.yml.example
@@ -29,6 +29,14 @@ app:
smtpUserName:
smtpPassword:
smtpFromAddress:
+
+ # Graphite Metric settings
+ # Allows those who use Graphite to have CommaFeed send metrics for graphing (time in seconds)
+ graphiteEnabled: false
+ graphitePrefix: "test.commafeed"
+ graphiteHost: "localhost"
+ graphitePort: 2003
+ graphiteInterval: 60
# wether this commafeed instance has a lot of feeds to refresh
# leave this to false in almost all cases
diff --git a/pom.xml b/pom.xml
index fb953af2..41549481 100644
--- a/pom.xml
+++ b/pom.xml
@@ -283,6 +283,11 @@
+
+ io.dropwizard.metrics
+ metrics-graphite
+ 3.1.2
+
org.apache.httpcomponents
diff --git a/src/main/java/com/commafeed/CommaFeedConfiguration.java b/src/main/java/com/commafeed/CommaFeedConfiguration.java
index 018b991e..14e5e17a 100644
--- a/src/main/java/com/commafeed/CommaFeedConfiguration.java
+++ b/src/main/java/com/commafeed/CommaFeedConfiguration.java
@@ -96,6 +96,12 @@ public class CommaFeedConfiguration extends Configuration {
private String smtpPassword;
private String smtpFromAddress;
+ private boolean graphiteEnabled;
+ private String graphitePrefix;
+ private String graphiteHost;
+ private int graphitePort;
+ private int graphiteInterval;
+
@NotNull
@Valid
private Boolean heavyLoad;
diff --git a/src/main/java/com/commafeed/CommaFeedModule.java b/src/main/java/com/commafeed/CommaFeedModule.java
index 9cb83429..a9a1b524 100644
--- a/src/main/java/com/commafeed/CommaFeedModule.java
+++ b/src/main/java/com/commafeed/CommaFeedModule.java
@@ -1,5 +1,7 @@
package com.commafeed;
+import java.net.InetSocketAddress;
+import java.util.concurrent.TimeUnit;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -7,6 +9,10 @@ import lombok.extern.slf4j.Slf4j;
import org.hibernate.SessionFactory;
import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.graphite.Graphite;
+import com.codahale.metrics.graphite.GraphiteReporter;
+import com.codahale.metrics.MetricFilter;
+import com.commafeed.CommaFeedConfiguration.ApplicationSettings;
import com.commafeed.CommaFeedConfiguration.CacheType;
import com.commafeed.backend.cache.CacheService;
import com.commafeed.backend.cache.NoopCacheService;
@@ -54,5 +60,27 @@ public class CommaFeedModule extends AbstractModule {
taskMultibinder.addBinding().to(OldEntriesCleanupTask.class);
taskMultibinder.addBinding().to(OrphanedFeedsCleanupTask.class);
taskMultibinder.addBinding().to(OrphanedContentsCleanupTask.class);
+
+ ApplicationSettings settings = config.getApplicationSettings();
+
+ if (settings.isGraphiteEnabled()) {
+ final String graphitePrefix = settings.getGraphitePrefix();
+ final String graphiteHost = settings.getGraphiteHost();
+ final int graphitePort = settings.getGraphitePort();
+ final int graphiteInterval = settings.getGraphiteInterval();
+
+ log.info("Graphite Metrics will be sent to host={}, port={}, prefix={}, interval={}sec", graphiteHost, graphitePort, graphitePrefix, graphiteInterval);
+
+ final Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
+ final GraphiteReporter reporter = GraphiteReporter.forRegistry(metrics)
+ .prefixedWith(graphitePrefix)
+ .convertRatesTo(TimeUnit.SECONDS)
+ .convertDurationsTo(TimeUnit.MILLISECONDS)
+ .filter(MetricFilter.ALL)
+ .build(graphite);
+ reporter.start(graphiteInterval, TimeUnit.SECONDS);
+ } else {
+ log.info("Graphite Metrics Disabled. Metrics will not be sent.");
+ }
}
}