diff --git a/src/main/java/org/datadog/jmxfetch/Instance.java b/src/main/java/org/datadog/jmxfetch/Instance.java index b5bece7c1..a6e9b322e 100644 --- a/src/main/java/org/datadog/jmxfetch/Instance.java +++ b/src/main/java/org/datadog/jmxfetch/Instance.java @@ -20,6 +20,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.Random; import javax.management.InstanceNotFoundException; import javax.management.MBeanAttributeInfo; @@ -270,10 +271,17 @@ public Instance( this.enableBeanSubscription = enableBeanSubscription != null && enableBeanSubscription; // Global override for enabling bean subscription on all instances - String enableSubscriptionOverride = System.getenv("DD_JMXFETCH_ENABLE_BEAN_SUBSCRIPTION"); + String enableSubscriptionOverride = System.getenv("DD_JMXFETCH_SUBSCRIPTION_ENABLED"); if (enableSubscriptionOverride != null && enableSubscriptionOverride.equalsIgnoreCase("true")) { this.enableBeanSubscription = true; } + String subscriptionCoinFlip = System.getenv("DD_JMXFETCH_SUBSCRIPTION_FLIPCOIN"); + if (subscriptionCoinFlip != null && subscriptionCoinFlip.equalsIgnoreCase("true")) { + Random rd = new Random(); + boolean enabled = rd.nextBoolean(); + this.enableBeanSubscription = enabled; + } + log.info("JMXFetch Subscription mode enabled={}", this.enableBeanSubscription); this.beanSubscriptionActive = false; } @@ -518,13 +526,16 @@ public synchronized List getMetrics() throws IOException { } long duration = System.currentTimeMillis() - this.lastCollectionTime; - log.info("Collection of {} matching attributes finished in {}ms", - matchingAttributes.size(), duration); + log.info("Collection finished in {}ms. MatchingAttributes={} CollectedMetrics={}", + duration, matchingAttributes.size(), metrics.size()); return metrics; } /** Returns whather or not the given period has elapsed since reference time. */ public boolean isPeriodDue(long refTime, Integer refPeriod) { + if (this.beanSubscriptionActive) { + return false; + } if ((System.currentTimeMillis() - refTime) / 1000 < refPeriod) { return false; } else {