Skip to content

Commit a7cc0ea

Browse files
committed
Add 'prefix' graphite parameter : value prepended to all metrics names which are sent to graphite
1 parent 1a48982 commit a7cc0ea

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

restx-monitor-admin/src/main/java/restx/monitor/GraphiteSettings.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ public interface GraphiteSettings {
2020
Optional<Integer> getFrequency();
2121
@SettingsKey(key = "graphite.reporter.frequency.unit", doc = "the unit in which frequency is expressed", defaultValue = "MINUTES")
2222
Optional<String> getFrequencyUnit();
23+
24+
@SettingsKey(key = "graphite.prefix", doc = "the value prepended to all metrics names which are sent to graphite")
25+
Optional<String> getPrefix();
2326
}

restx-monitor-admin/src/main/java/restx/monitor/MetricsConfiguration.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,16 @@ private void setupGraphiteReporter() {
8080
InetSocketAddress address = new InetSocketAddress(
8181
graphiteSettings.getGraphiteHost().get(), graphiteSettings.getGraphitePort().or(2003));
8282
logger.info("Initializing Metrics Graphite reporting to {}", address);
83-
GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metrics)
83+
84+
GraphiteReporter.Builder builder = GraphiteReporter.forRegistry(metrics);
85+
86+
if (graphiteSettings.getPrefix().isPresent()) {
87+
String prefix = graphiteSettings.getPrefix().get();
88+
builder.prefixedWith(prefix);
89+
logger.info("Metrics Graphite prefix is set to '{}'", prefix);
90+
}
91+
92+
GraphiteReporter graphiteReporter = builder
8493
.convertRatesTo(TimeUnit.SECONDS)
8594
.convertDurationsTo(TimeUnit.MILLISECONDS)
8695
.build(new Graphite(address));

0 commit comments

Comments
 (0)