forked from Archives/Athou_commafeed
Add feature to emit Graphite metrics based on configuration
This commit is contained in:
@@ -28,6 +28,14 @@ app:
|
|||||||
smtpTls: false
|
smtpTls: false
|
||||||
smtpUserName: user
|
smtpUserName: user
|
||||||
smtpPassword: pass
|
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
|
# wether this commafeed instance has a lot of feeds to refresh
|
||||||
# leave this to false in almost all cases
|
# leave this to false in almost all cases
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ app:
|
|||||||
smtpUserName:
|
smtpUserName:
|
||||||
smtpPassword:
|
smtpPassword:
|
||||||
smtpFromAddress:
|
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
|
# wether this commafeed instance has a lot of feeds to refresh
|
||||||
# leave this to false in almost all cases
|
# leave this to false in almost all cases
|
||||||
|
|||||||
5
pom.xml
5
pom.xml
@@ -283,6 +283,11 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.dropwizard.metrics</groupId>
|
||||||
|
<artifactId>metrics-graphite</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
|||||||
@@ -96,6 +96,12 @@ public class CommaFeedConfiguration extends Configuration {
|
|||||||
private String smtpPassword;
|
private String smtpPassword;
|
||||||
private String smtpFromAddress;
|
private String smtpFromAddress;
|
||||||
|
|
||||||
|
private boolean graphiteEnabled;
|
||||||
|
private String graphitePrefix;
|
||||||
|
private String graphiteHost;
|
||||||
|
private int graphitePort;
|
||||||
|
private int graphiteInterval;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Valid
|
@Valid
|
||||||
private Boolean heavyLoad;
|
private Boolean heavyLoad;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.commafeed;
|
package com.commafeed;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -7,6 +9,10 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
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.CommaFeedConfiguration.CacheType;
|
||||||
import com.commafeed.backend.cache.CacheService;
|
import com.commafeed.backend.cache.CacheService;
|
||||||
import com.commafeed.backend.cache.NoopCacheService;
|
import com.commafeed.backend.cache.NoopCacheService;
|
||||||
@@ -54,5 +60,27 @@ public class CommaFeedModule extends AbstractModule {
|
|||||||
taskMultibinder.addBinding().to(OldEntriesCleanupTask.class);
|
taskMultibinder.addBinding().to(OldEntriesCleanupTask.class);
|
||||||
taskMultibinder.addBinding().to(OrphanedFeedsCleanupTask.class);
|
taskMultibinder.addBinding().to(OrphanedFeedsCleanupTask.class);
|
||||||
taskMultibinder.addBinding().to(OrphanedContentsCleanupTask.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.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user