From e3ec8507a19569cdc7788657df46992a0f0c622f Mon Sep 17 00:00:00 2001 From: Paul Moineau Date: Wed, 11 Sep 2024 16:16:39 -0400 Subject: [PATCH] W-16656937: add graphite.prefix.includeHostname property --- .../main/java/com/demandware/core/config/cfgMetric.java | 5 ++++- .../src/main/java/com/demandware/core/metric/Util.java | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/carbonj.service/src/main/java/com/demandware/core/config/cfgMetric.java b/carbonj.service/src/main/java/com/demandware/core/config/cfgMetric.java index 75485601..083df5e3 100644 --- a/carbonj.service/src/main/java/com/demandware/core/config/cfgMetric.java +++ b/carbonj.service/src/main/java/com/demandware/core/config/cfgMetric.java @@ -58,6 +58,8 @@ NameUtils nameUtils() @Value( "${graphite.prefix:}" ) private String graphitePrefix; + @Value( "${graphite.prefix.includeHostname:false}" ) private boolean graphitePrefixIncludeHostname; + @Value( "${dw.podId:-1}" ) private int podId; @Value( "${dw.groupId:}" ) private String groupId; @@ -82,7 +84,8 @@ NameUtils nameUtils() { GraphiteReporter graphiteReporter = Util.getGraphiteReporter( metricRegistry, graphiteHost, graphitePort, graphiteTransport, - Util.getGraphiteMetricPrefix( graphitePrefix, podId, groupId, svcVersion ) ); + Util.getGraphiteMetricPrefix( graphitePrefix, graphitePrefixIncludeHostname, + podId, groupId, svcVersion ) ); if ( graphiteReporter != null ) { graphiteReporter.start( 60, TimeUnit.SECONDS ); diff --git a/carbonj.service/src/main/java/com/demandware/core/metric/Util.java b/carbonj.service/src/main/java/com/demandware/core/metric/Util.java index 4c0df9cf..4ab8e1a3 100644 --- a/carbonj.service/src/main/java/com/demandware/core/metric/Util.java +++ b/carbonj.service/src/main/java/com/demandware/core/metric/Util.java @@ -24,8 +24,8 @@ public class Util private static GraphiteReporter graphiteReporter = null; - public static String getGraphiteMetricPrefix( String graphiteMetricsPrefix, int podId, String groupId, - String version ) + public static String getGraphiteMetricPrefix( String graphiteMetricsPrefix, boolean graphitePrefixIncludeHostname, + int podId, String groupId, String version ) throws UnknownHostException { String fqdn = InetAddress.getLocalHost().getHostName(); @@ -40,6 +40,10 @@ else if ( StringUtils.isEmpty( graphiteMetricsPrefix ) ) { graphiteMetricsPrefix = "um.dev.carbonj." + hostname; } + else if ( graphitePrefixIncludeHostname ) + { + graphiteMetricsPrefix = graphiteMetricsPrefix + "." + hostname; + } return graphiteMetricsPrefix; }