Skip to content

Commit

Permalink
Add 'prefix' graphite parameter : value prepended to all metrics name…
Browse files Browse the repository at this point in the history
…s which are sent to graphite
  • Loading branch information
walien committed Dec 18, 2014
1 parent 1a48982 commit a7cc0ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public interface GraphiteSettings {
Optional<Integer> getFrequency();
@SettingsKey(key = "graphite.reporter.frequency.unit", doc = "the unit in which frequency is expressed", defaultValue = "MINUTES")
Optional<String> getFrequencyUnit();

@SettingsKey(key = "graphite.prefix", doc = "the value prepended to all metrics names which are sent to graphite")
Optional<String> getPrefix();
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ private void setupGraphiteReporter() {
InetSocketAddress address = new InetSocketAddress(
graphiteSettings.getGraphiteHost().get(), graphiteSettings.getGraphitePort().or(2003));
logger.info("Initializing Metrics Graphite reporting to {}", address);
GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metrics)

GraphiteReporter.Builder builder = GraphiteReporter.forRegistry(metrics);

if (graphiteSettings.getPrefix().isPresent()) {
String prefix = graphiteSettings.getPrefix().get();
builder.prefixedWith(prefix);
logger.info("Metrics Graphite prefix is set to '{}'", prefix);
}

GraphiteReporter graphiteReporter = builder
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build(new Graphite(address));
Expand Down

0 comments on commit a7cc0ea

Please sign in to comment.