diff --git a/src/main/java/org/datadog/jmxfetch/App.java b/src/main/java/org/datadog/jmxfetch/App.java index 8c78e8ac..9c40f02c 100644 --- a/src/main/java/org/datadog/jmxfetch/App.java +++ b/src/main/java/org/datadog/jmxfetch/App.java @@ -133,7 +133,10 @@ public App(final AppConfig appConfig) { } this.configs = getConfigs(this.appConfig); - this.initTelemetryBean(); + if (this.appConfig.getJmxfetchTelemetry()) { + log.info("Enabling JMX Fetch Telemetry"); + this.initTelemetryBean(); + } } private ObjectName getAppTelemetryBeanName() { @@ -176,6 +179,9 @@ private void initTelemetryBean() { } private void teardownTelemetry() { + if (!this.appConfig.getJmxfetchTelemetry()) { + return; + } MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName appTelemetryBeanName = getAppTelemetryBeanName(); if (appTelemetryBeanName == null) { diff --git a/src/test/java/org/datadog/jmxfetch/TestApp.java b/src/test/java/org/datadog/jmxfetch/TestApp.java index 5fec8d25..a46b0c26 100644 --- a/src/test/java/org/datadog/jmxfetch/TestApp.java +++ b/src/test/java/org/datadog/jmxfetch/TestApp.java @@ -22,6 +22,9 @@ public class TestApp extends TestCommon { /** Tag metrics with MBean parameters based on user supplied regex */ @Test public void testBeanRegexTags() throws Exception { + // When we enable JMXFetch telemetry + when(appConfig.getJmxfetchTelemetry()).thenReturn(true); + // We expose a few metrics through JMX registerMBean( new SimpleTestJavaApp(), @@ -53,6 +56,9 @@ public void testBeanRegexTags() throws Exception { /** Tag metrics with MBeans parameters. */ @Test public void testBeanTags() throws Exception { + // When we enable JMXFetch telemetry + when(appConfig.getJmxfetchTelemetry()).thenReturn(true); + // We expose a few metrics through JMX registerMBean( new SimpleTestJavaApp(),