* @param environment the {@link Service} environment
*/
public void run(final GraphiteReportingConfiguration configuration,
final Environment environment) {
final GraphiteConfiguration graphiteConfiguration = configuration.getGraphite();
if (graphiteConfiguration.getEnabled()) {
log.info("Reporting metrics to Graphite at {}:{}, every {}",
graphiteConfiguration.getHost(),
graphiteConfiguration.getPort(),
graphiteConfiguration.getFrequency());
GraphiteReporter.enable(
Metrics.defaultRegistry(),
graphiteConfiguration.getFrequency().toNanoseconds(),
TimeUnit.NANOSECONDS,
graphiteConfiguration.getHost(),
graphiteConfiguration.getPort(),
graphiteConfiguration.getPrefix(),
new MetricPredicate() {
@Override
public boolean matches(final MetricName name, final Metric metric) {
return !graphiteConfiguration.getExcludes().contains(pathFor(name));
}
private String pathFor(final MetricName name) {
final StringBuilder sb = new StringBuilder(name.getGroup())
.append('.')
.append(name.getType())
.append('.');
if (name.hasScope()) {
sb.append(name.getScope()).append('.');
}
return sb.append(name.getName()).toString();
}
}
);
environment.addHealthCheck(new GraphiteHealthCheck(
graphiteConfiguration.getHost(),
graphiteConfiguration.getPort(),
"graphite"));
}
}