Skip to content

Commit c6bcdb7

Browse files
authored
Allow the metrics client sink to be configured separately from the daemon host and port; however, if not specified fallback to the daemon host and port for backwards compatibility. (#98)
1 parent 054dff1 commit c6bcdb7

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/main/java/com/arpnetworking/metrics/mad/Main.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ private Injector launchGuice(final ActorSystem actorSystem) {
255255
}
256256

257257
// Instantiate the metrics factory
258-
final String sinkHost = "0.0.0.0".equals(_configuration.getHttpHost()) ? "localhost" : _configuration.getHttpHost();
259-
final URI sinkUrl = URI.create("http://" + sinkHost + ":" + _configuration.getHttpPort() + "/metrics/v2/application");
258+
final URI sinkUrl = URI.create(
259+
"http://" + _configuration.getMetricsClientHost() + ":"
260+
+ _configuration.getMetricsClientPort() + "/metrics/v2/application");
260261
final MetricsFactory metricsFactory = new TsdMetricsFactory.Builder()
261262
.setClusterName(_configuration.getMonitoringCluster())
262263
.setServiceName("mad")

src/main/java/com/arpnetworking/metrics/mad/configuration/AggregatorConfiguration.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ public Optional<Class<? extends SupplementalRoutes>> getSupplementalHttpRoutesCl
6969
return _supplementalHttpRoutesClass;
7070
}
7171

72+
public String getMetricsClientHost() {
73+
return _metricsClientHost;
74+
}
75+
76+
public Integer getMetricsClientPort() {
77+
return _metricsClientPort;
78+
}
79+
7280
public Duration getJvmMetricsCollectionInterval() {
7381
return _jvmMetricsCollectionInterval;
7482
}
@@ -90,6 +98,8 @@ public String toString() {
9098
.add("HttpStatusPath", _httpStatusPath)
9199
.add("SupplementalHttpRoutesClass", _supplementalHttpRoutesClass)
92100
.add("AkkaConfiguration", _akkaConfiguration)
101+
.add("MetricsClientHost", _metricsClientHost)
102+
.add("MetricsClientPort", _metricsClientPort)
93103
.add("JvmMetricsCollectorInterval", _jvmMetricsCollectionInterval)
94104
.toString();
95105
}
@@ -103,6 +113,9 @@ private AggregatorConfiguration(final Builder builder) {
103113
_httpHealthCheckPath = builder._httpHealthCheckPath;
104114
_httpStatusPath = builder._httpStatusPath;
105115
_supplementalHttpRoutesClass = Optional.ofNullable(builder._supplementalHttpRoutesClass);
116+
_metricsClientHost = Optional.ofNullable(builder._metricsClientHost).orElse(
117+
"0.0.0.0".equals(_httpHost) ? "localhost" : _httpHost);
118+
_metricsClientPort = Optional.ofNullable(builder._metricsClientPort).orElse(_httpPort);
106119
_jvmMetricsCollectionInterval = builder._jvmMetricsCollectionInterval;
107120
_akkaConfiguration = builder._akkaConfiguration;
108121
}
@@ -115,6 +128,8 @@ private AggregatorConfiguration(final Builder builder) {
115128
private final String _httpStatusPath;
116129
private final int _httpPort;
117130
private Optional<Class<? extends SupplementalRoutes>> _supplementalHttpRoutesClass;
131+
private final String _metricsClientHost;
132+
private final int _metricsClientPort;
118133
private final Duration _jvmMetricsCollectionInterval;
119134
private final Map<String, ?> _akkaConfiguration;
120135

@@ -221,6 +236,31 @@ public Builder setSupplementalHttpRoutesClass(final Class<? extends Supplemental
221236
return this;
222237
}
223238

239+
/**
240+
* The metrics client http host address to send to. Optional. Cannot be
241+
* empty. Defaults to the http address unless it's 0.0.0.0 in which
242+
* case it defaults to localhost.
243+
*
244+
* @param value The metrics client host address to send to.
245+
* @return This instance of <code>Builder</code>.
246+
*/
247+
public Builder setMetricsClientHost(final String value) {
248+
_metricsClientHost = value;
249+
return this;
250+
}
251+
252+
/**
253+
* The metrics client http port to send to. Optional. must be between
254+
* 1 and 65535 (inclusive). Defaults to the http port.
255+
*
256+
* @param value The metrics client port to listen send to.
257+
* @return This instance of <code>Builder</code>.
258+
*/
259+
public Builder setMetricsClientPort(final Integer value) {
260+
_metricsClientPort = value;
261+
return this;
262+
}
263+
224264
/**
225265
* Period for collecting JVM metrics. Optional. Default is 500 milliseconds.
226266
*
@@ -269,6 +309,10 @@ public Builder setAkkaConfiguration(final Map<String, ?> value) {
269309
@NotEmpty
270310
private String _httpStatusPath = "/status";
271311
private Class<? extends SupplementalRoutes> _supplementalHttpRoutesClass;
312+
@NotEmpty
313+
private String _metricsClientHost;
314+
@Range(min = 1, max = 65535)
315+
private Integer _metricsClientPort;
272316
@NotNull
273317
private Duration _jvmMetricsCollectionInterval = Duration.ofMillis(500);
274318
@NotNull

0 commit comments

Comments
 (0)