Configure jmxfetch host and port separately
This commit is contained in:
parent
97fe8cbf88
commit
60f799dd5a
|
@ -10,7 +10,6 @@ import org.datadog.jmxfetch.AppConfig;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class JMXFetch {
|
public class JMXFetch {
|
||||||
|
|
||||||
public static final int DEFAULT_STATSD_PORT = 8125;
|
|
||||||
public static final ImmutableList<String> DEFAULT_CONFIGS =
|
public static final ImmutableList<String> DEFAULT_CONFIGS =
|
||||||
ImmutableList.of("jmxfetch-config.yaml");
|
ImmutableList.of("jmxfetch-config.yaml");
|
||||||
|
|
||||||
|
@ -76,11 +75,17 @@ public class JMXFetch {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getReporter() {
|
private static String getReporter() {
|
||||||
String reporter = Config.get().getJmxFetchReporter();
|
final Config config = Config.get();
|
||||||
if (reporter == null) {
|
if (Config.LOGGING_WRITER_TYPE.equals(config.getWriterType())) {
|
||||||
reporter = "statsd:" + Config.get().getAgentHost() + ":" + DEFAULT_STATSD_PORT;
|
// If logging writer is enabled then also enable console reporter in JMXFetch
|
||||||
|
return "console";
|
||||||
}
|
}
|
||||||
return reporter;
|
|
||||||
|
final String host =
|
||||||
|
config.getJmxFetchStatsdHost() == null
|
||||||
|
? config.getAgentHost()
|
||||||
|
: config.getJmxFetchStatsdHost();
|
||||||
|
return "statsd:" + host + ":" + config.getJmxFetchStatsdPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getLogLocation() {
|
private static String getLogLocation() {
|
||||||
|
|
|
@ -40,7 +40,8 @@ public class Config {
|
||||||
public static final String JMX_FETCH_METRICS_CONFIGS = "jmxfetch.metrics-configs";
|
public static final String JMX_FETCH_METRICS_CONFIGS = "jmxfetch.metrics-configs";
|
||||||
public static final String JMX_FETCH_CHECK_PERIOD = "jmxfetch.check-period";
|
public static final String JMX_FETCH_CHECK_PERIOD = "jmxfetch.check-period";
|
||||||
public static final String JMX_FETCH_REFRESH_BEANS_PERIOD = "jmxfetch.refresh-beans-period";
|
public static final String JMX_FETCH_REFRESH_BEANS_PERIOD = "jmxfetch.refresh-beans-period";
|
||||||
public static final String JMX_FETCH_REPORTER = "jmxfetch.reporter";
|
public static final String JMX_FETCH_STATSD_HOST = "jmxfetch.statsd.host";
|
||||||
|
public static final String JMX_FETCH_STATSD_PORT = "jmxfetch.statsd.port";
|
||||||
|
|
||||||
public static final String DEFAULT_SERVICE_NAME = "unnamed-java-app";
|
public static final String DEFAULT_SERVICE_NAME = "unnamed-java-app";
|
||||||
|
|
||||||
|
@ -55,6 +56,8 @@ public class Config {
|
||||||
private static final boolean DEFAULT_TRACE_RESOLVER_ENABLED = true;
|
private static final boolean DEFAULT_TRACE_RESOLVER_ENABLED = true;
|
||||||
private static final boolean DEFAULT_JMX_FETCH_ENABLED = false;
|
private static final boolean DEFAULT_JMX_FETCH_ENABLED = false;
|
||||||
|
|
||||||
|
public static final int DEFAULT_JMX_FETCH_STATSD_PORT = 8125;
|
||||||
|
|
||||||
@Getter private final String serviceName;
|
@Getter private final String serviceName;
|
||||||
@Getter private final String writerType;
|
@Getter private final String writerType;
|
||||||
@Getter private final String agentHost;
|
@Getter private final String agentHost;
|
||||||
|
@ -68,7 +71,8 @@ public class Config {
|
||||||
@Getter private final List<String> jmxFetchMetricsConfigs;
|
@Getter private final List<String> jmxFetchMetricsConfigs;
|
||||||
@Getter private final Integer jmxFetchCheckPeriod;
|
@Getter private final Integer jmxFetchCheckPeriod;
|
||||||
@Getter private final Integer jmxFetchRefreshBeansPeriod;
|
@Getter private final Integer jmxFetchRefreshBeansPeriod;
|
||||||
@Getter private final String jmxFetchReporter;
|
@Getter private final String jmxFetchStatsdHost;
|
||||||
|
@Getter private final Integer jmxFetchStatsdPort;
|
||||||
|
|
||||||
// Read order: System Properties -> Env Variables, [-> default value]
|
// Read order: System Properties -> Env Variables, [-> default value]
|
||||||
// Visible for testing
|
// Visible for testing
|
||||||
|
@ -90,7 +94,9 @@ public class Config {
|
||||||
jmxFetchCheckPeriod = getIntegerSettingFromEnvironment(JMX_FETCH_CHECK_PERIOD, null);
|
jmxFetchCheckPeriod = getIntegerSettingFromEnvironment(JMX_FETCH_CHECK_PERIOD, null);
|
||||||
jmxFetchRefreshBeansPeriod =
|
jmxFetchRefreshBeansPeriod =
|
||||||
getIntegerSettingFromEnvironment(JMX_FETCH_REFRESH_BEANS_PERIOD, null);
|
getIntegerSettingFromEnvironment(JMX_FETCH_REFRESH_BEANS_PERIOD, null);
|
||||||
jmxFetchReporter = getSettingFromEnvironment(JMX_FETCH_REPORTER, null);
|
jmxFetchStatsdHost = getSettingFromEnvironment(JMX_FETCH_STATSD_HOST, null);
|
||||||
|
jmxFetchStatsdPort =
|
||||||
|
getIntegerSettingFromEnvironment(JMX_FETCH_STATSD_PORT, DEFAULT_JMX_FETCH_STATSD_PORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read order: Properties -> Parent
|
// Read order: Properties -> Parent
|
||||||
|
@ -115,7 +121,9 @@ public class Config {
|
||||||
jmxFetchRefreshBeansPeriod =
|
jmxFetchRefreshBeansPeriod =
|
||||||
getPropertyIntegerValue(
|
getPropertyIntegerValue(
|
||||||
properties, JMX_FETCH_REFRESH_BEANS_PERIOD, parent.jmxFetchRefreshBeansPeriod);
|
properties, JMX_FETCH_REFRESH_BEANS_PERIOD, parent.jmxFetchRefreshBeansPeriod);
|
||||||
jmxFetchReporter = properties.getProperty(JMX_FETCH_REPORTER, parent.jmxFetchReporter);
|
jmxFetchStatsdHost = properties.getProperty(JMX_FETCH_STATSD_HOST, parent.jmxFetchStatsdHost);
|
||||||
|
jmxFetchStatsdPort =
|
||||||
|
getPropertyIntegerValue(properties, JMX_FETCH_STATSD_PORT, parent.jmxFetchStatsdPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getSettingFromEnvironment(final String name, final String defaultValue) {
|
private static String getSettingFromEnvironment(final String name, final String defaultValue) {
|
||||||
|
|
|
@ -13,11 +13,13 @@ import static Config.SERVICE_MAPPING
|
||||||
import static Config.SERVICE_NAME
|
import static Config.SERVICE_NAME
|
||||||
import static Config.SPAN_TAGS
|
import static Config.SPAN_TAGS
|
||||||
import static Config.WRITER_TYPE
|
import static Config.WRITER_TYPE
|
||||||
|
import static datadog.trace.api.Config.DEFAULT_JMX_FETCH_STATSD_PORT
|
||||||
import static datadog.trace.api.Config.JMX_FETCH_CHECK_PERIOD
|
import static datadog.trace.api.Config.JMX_FETCH_CHECK_PERIOD
|
||||||
import static datadog.trace.api.Config.JMX_FETCH_ENABLED
|
import static datadog.trace.api.Config.JMX_FETCH_ENABLED
|
||||||
import static datadog.trace.api.Config.JMX_FETCH_METRICS_CONFIGS
|
import static datadog.trace.api.Config.JMX_FETCH_METRICS_CONFIGS
|
||||||
import static datadog.trace.api.Config.JMX_FETCH_REFRESH_BEANS_PERIOD
|
import static datadog.trace.api.Config.JMX_FETCH_REFRESH_BEANS_PERIOD
|
||||||
import static datadog.trace.api.Config.JMX_FETCH_REPORTER
|
import static datadog.trace.api.Config.JMX_FETCH_STATSD_HOST
|
||||||
|
import static datadog.trace.api.Config.JMX_FETCH_STATSD_PORT
|
||||||
import static datadog.trace.api.Config.PRIORITY_SAMPLING
|
import static datadog.trace.api.Config.PRIORITY_SAMPLING
|
||||||
import static datadog.trace.api.Config.TRACE_RESOLVER_ENABLED
|
import static datadog.trace.api.Config.TRACE_RESOLVER_ENABLED
|
||||||
|
|
||||||
|
@ -51,7 +53,8 @@ class ConfigTest extends Specification {
|
||||||
config.jmxFetchMetricsConfigs == []
|
config.jmxFetchMetricsConfigs == []
|
||||||
config.jmxFetchCheckPeriod == null
|
config.jmxFetchCheckPeriod == null
|
||||||
config.jmxFetchRefreshBeansPeriod == null
|
config.jmxFetchRefreshBeansPeriod == null
|
||||||
config.jmxFetchReporter == null
|
config.jmxFetchStatsdHost == null
|
||||||
|
config.jmxFetchStatsdPort == DEFAULT_JMX_FETCH_STATSD_PORT
|
||||||
config.toString().contains("unnamed-java-app")
|
config.toString().contains("unnamed-java-app")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +73,8 @@ class ConfigTest extends Specification {
|
||||||
System.setProperty(PREFIX + JMX_FETCH_METRICS_CONFIGS, "/foo.yaml,/bar.yaml")
|
System.setProperty(PREFIX + JMX_FETCH_METRICS_CONFIGS, "/foo.yaml,/bar.yaml")
|
||||||
System.setProperty(PREFIX + JMX_FETCH_CHECK_PERIOD, "100")
|
System.setProperty(PREFIX + JMX_FETCH_CHECK_PERIOD, "100")
|
||||||
System.setProperty(PREFIX + JMX_FETCH_REFRESH_BEANS_PERIOD, "200")
|
System.setProperty(PREFIX + JMX_FETCH_REFRESH_BEANS_PERIOD, "200")
|
||||||
System.setProperty(PREFIX + JMX_FETCH_REPORTER, "reporter")
|
System.setProperty(PREFIX + JMX_FETCH_STATSD_HOST, "statsd host")
|
||||||
|
System.setProperty(PREFIX + JMX_FETCH_STATSD_PORT, "321")
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def config = new Config()
|
def config = new Config()
|
||||||
|
@ -89,7 +93,8 @@ class ConfigTest extends Specification {
|
||||||
config.jmxFetchMetricsConfigs == ["/foo.yaml", "/bar.yaml"]
|
config.jmxFetchMetricsConfigs == ["/foo.yaml", "/bar.yaml"]
|
||||||
config.jmxFetchCheckPeriod == 100
|
config.jmxFetchCheckPeriod == 100
|
||||||
config.jmxFetchRefreshBeansPeriod == 200
|
config.jmxFetchRefreshBeansPeriod == 200
|
||||||
config.jmxFetchReporter == "reporter"
|
config.jmxFetchStatsdHost == "statsd host"
|
||||||
|
config.jmxFetchStatsdPort == 321
|
||||||
}
|
}
|
||||||
|
|
||||||
def "specify overrides via env vars"() {
|
def "specify overrides via env vars"() {
|
||||||
|
@ -140,7 +145,8 @@ class ConfigTest extends Specification {
|
||||||
properties.setProperty(JMX_FETCH_METRICS_CONFIGS, "/foo.yaml,/bar.yaml")
|
properties.setProperty(JMX_FETCH_METRICS_CONFIGS, "/foo.yaml,/bar.yaml")
|
||||||
properties.setProperty(JMX_FETCH_CHECK_PERIOD, "100")
|
properties.setProperty(JMX_FETCH_CHECK_PERIOD, "100")
|
||||||
properties.setProperty(JMX_FETCH_REFRESH_BEANS_PERIOD, "200")
|
properties.setProperty(JMX_FETCH_REFRESH_BEANS_PERIOD, "200")
|
||||||
properties.setProperty(JMX_FETCH_REPORTER, "reporter")
|
properties.setProperty(JMX_FETCH_STATSD_HOST, "statsd host")
|
||||||
|
properties.setProperty(JMX_FETCH_STATSD_PORT, "321")
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def config = Config.get(properties)
|
def config = Config.get(properties)
|
||||||
|
@ -158,7 +164,8 @@ class ConfigTest extends Specification {
|
||||||
config.jmxFetchMetricsConfigs == ["/foo.yaml", "/bar.yaml"]
|
config.jmxFetchMetricsConfigs == ["/foo.yaml", "/bar.yaml"]
|
||||||
config.jmxFetchCheckPeriod == 100
|
config.jmxFetchCheckPeriod == 100
|
||||||
config.jmxFetchRefreshBeansPeriod == 200
|
config.jmxFetchRefreshBeansPeriod == 200
|
||||||
config.jmxFetchReporter == "reporter"
|
config.jmxFetchStatsdHost == "statsd host"
|
||||||
|
config.jmxFetchStatsdPort == 321
|
||||||
}
|
}
|
||||||
|
|
||||||
def "override null properties"() {
|
def "override null properties"() {
|
||||||
|
|
Loading…
Reference in New Issue