|
19 | 19 | import java.util.List; |
20 | 20 | import java.util.Map; |
21 | 21 | import java.util.Map.Entry; |
| 22 | +import java.util.Random; |
22 | 23 | import java.util.Set; |
23 | 24 |
|
24 | 25 | import javax.management.InstanceNotFoundException; |
@@ -270,10 +271,18 @@ public Instance( |
270 | 271 | this.enableBeanSubscription = enableBeanSubscription != null && enableBeanSubscription; |
271 | 272 |
|
272 | 273 | // Global override for enabling bean subscription on all instances |
273 | | - String enableSubscriptionOverride = System.getenv("DD_JMXFETCH_ENABLE_BEAN_SUBSCRIPTION"); |
274 | | - if (enableSubscriptionOverride != null && enableSubscriptionOverride.equalsIgnoreCase("true")) { |
| 274 | + String enableSubscriptionOverride = System.getenv("DD_JMXFETCH_SUBSCRIPTION_ENABLED"); |
| 275 | + if (enableSubscriptionOverride != null |
| 276 | + && enableSubscriptionOverride.equalsIgnoreCase("true")) { |
275 | 277 | this.enableBeanSubscription = true; |
276 | 278 | } |
| 279 | + String subscriptionCoinFlip = System.getenv("DD_JMXFETCH_SUBSCRIPTION_FLIPCOIN"); |
| 280 | + if (subscriptionCoinFlip != null && subscriptionCoinFlip.equalsIgnoreCase("true")) { |
| 281 | + Random rd = new Random(); |
| 282 | + boolean enabled = rd.nextBoolean(); |
| 283 | + this.enableBeanSubscription = enabled; |
| 284 | + } |
| 285 | + log.info("JMXFetch Subscription mode enabled={}", this.enableBeanSubscription); |
277 | 286 | this.beanSubscriptionActive = false; |
278 | 287 | } |
279 | 288 |
|
@@ -518,13 +527,16 @@ public synchronized List<Metric> getMetrics() throws IOException { |
518 | 527 | } |
519 | 528 |
|
520 | 529 | long duration = System.currentTimeMillis() - this.lastCollectionTime; |
521 | | - log.info("Collection of {} matching attributes finished in {}ms", |
522 | | - matchingAttributes.size(), duration); |
| 530 | + log.info("Collection finished in {}ms. MatchingAttributes={} CollectedMetrics={}", |
| 531 | + duration, matchingAttributes.size(), metrics.size()); |
523 | 532 | return metrics; |
524 | 533 | } |
525 | 534 |
|
526 | 535 | /** Returns whather or not the given period has elapsed since reference time. */ |
527 | 536 | public boolean isPeriodDue(long refTime, Integer refPeriod) { |
| 537 | + if (this.beanSubscriptionActive) { |
| 538 | + return false; |
| 539 | + } |
528 | 540 | if ((System.currentTimeMillis() - refTime) / 1000 < refPeriod) { |
529 | 541 | return false; |
530 | 542 | } else { |
|
0 commit comments