diff --git a/src/main/java/org/datadog/jmxfetch/Configuration.java b/src/main/java/org/datadog/jmxfetch/Configuration.java index 0960c98f5..41b77e678 100644 --- a/src/main/java/org/datadog/jmxfetch/Configuration.java +++ b/src/main/java/org/datadog/jmxfetch/Configuration.java @@ -1,5 +1,7 @@ package org.datadog.jmxfetch; +import org.datadog.jmxfetch.util.InstanceTelemetry; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -9,6 +11,7 @@ import java.util.Map.Entry; import java.util.Set; + public class Configuration { private Map conf; @@ -194,7 +197,6 @@ private static Map> getCommonScopeByDomain( } commonScopeByDomain.put(domainName, commonScope); } - return commonScopeByDomain; } @@ -231,8 +233,7 @@ private static String beanScopeToString( * @param configurationList the configuration list to process * @return common bean pattern strings */ - public static List getGreatestCommonScopes( - List configurationList) { + public static List getGreatestCommonScopes(List configurationList) { List includeConfigList = getIncludeConfigurationList(configurationList); Map> includeFiltersByDomain = diff --git a/src/main/java/org/datadog/jmxfetch/Instance.java b/src/main/java/org/datadog/jmxfetch/Instance.java index 770a8f863..f7b138739 100644 --- a/src/main/java/org/datadog/jmxfetch/Instance.java +++ b/src/main/java/org/datadog/jmxfetch/Instance.java @@ -576,11 +576,14 @@ private void getMatchingAttributes() throws IOException { this.failingAttributes.clear(); int metricsCount = 0; + int beansWithAttributeMatch = 0; + if (!action.equals(AppConfig.ACTION_COLLECT)) { reporter.displayInstanceName(this); } for (ObjectName beanName : this.beans) { + boolean attributeMatched = false; if (limitReached) { log.debug("Limit reached"); if (action.equals(AppConfig.ACTION_COLLECT)) { @@ -730,8 +733,18 @@ private void getMatchingAttributes() throws IOException { || action.equals(AppConfig.ACTION_LIST_NOT_MATCHING))) { reporter.displayNonMatchingAttributeName(jmxAttribute); } + if (jmxAttribute.getMatchingConf() != null) { + attributeMatched = true; + } + } + if (attributeMatched) { + beansWithAttributeMatch += 1; } } + if (instanceTelemetryBean != null) { + instanceTelemetryBean.setAttributeMatchRatio((double) + beansWithAttributeMatch / beans.size()); + } log.info("Found {} matching attributes", matchingAttributes.size()); } @@ -761,6 +774,9 @@ private void refreshBeansList() throws IOException { ObjectName name = new ObjectName(scope); this.beans.addAll(connection.queryNames(name)); } + if (instanceTelemetryBean != null) { + instanceTelemetryBean.setDomainsQueried(beanScopes.size()); + } } catch (Exception e) { log.error( "Unable to compute a common bean scope, querying all beans as a fallback", diff --git a/src/main/java/org/datadog/jmxfetch/Status.java b/src/main/java/org/datadog/jmxfetch/Status.java index e6ecfc494..8cc786a9d 100644 --- a/src/main/java/org/datadog/jmxfetch/Status.java +++ b/src/main/java/org/datadog/jmxfetch/Status.java @@ -127,6 +127,9 @@ private void addStats( instStats.put("instance_attribute_count", instanceTelemetryBean.getTopLevelAttributeCount()); instStats.put("instance_metric_count", instanceTelemetryBean.getMetricCount()); + instStats.put("instance_domains_queried", instanceTelemetryBean.getDomainsQueried()); + instStats.put("instance_attribute_match_ratio", + instanceTelemetryBean.getAttributeMatchRatio()); } instStats.put("message", message); instStats.put("status", status); diff --git a/src/main/java/org/datadog/jmxfetch/util/InstanceTelemetry.java b/src/main/java/org/datadog/jmxfetch/util/InstanceTelemetry.java index b216b54f5..1e9124846 100644 --- a/src/main/java/org/datadog/jmxfetch/util/InstanceTelemetry.java +++ b/src/main/java/org/datadog/jmxfetch/util/InstanceTelemetry.java @@ -7,6 +7,8 @@ public class InstanceTelemetry implements InstanceTelemetryMBean { private int beansFetched; private int topLevelAttributeCount; private int metricCount; + private int domainsQueried; + private double attributeMatchRatio; /** Jmxfetch telemetry bean constructor. */ public InstanceTelemetry() { @@ -27,6 +29,13 @@ public int getMetricCount() { return metricCount; } + public int getDomainsQueried() { + return domainsQueried; + } + + public double getAttributeMatchRatio() { + return attributeMatchRatio; + } public void setBeansFetched(int count) { beansFetched = count; @@ -40,5 +49,12 @@ public void setMetricCount(int count) { metricCount = count; } + public void setDomainsQueried(int count) { + domainsQueried = count; + } + + public void setAttributeMatchRatio(double ratio) { + attributeMatchRatio = ratio; + } } diff --git a/src/main/java/org/datadog/jmxfetch/util/InstanceTelemetryMBean.java b/src/main/java/org/datadog/jmxfetch/util/InstanceTelemetryMBean.java index b80d126c0..3f5b028c4 100644 --- a/src/main/java/org/datadog/jmxfetch/util/InstanceTelemetryMBean.java +++ b/src/main/java/org/datadog/jmxfetch/util/InstanceTelemetryMBean.java @@ -8,4 +8,6 @@ public interface InstanceTelemetryMBean { int getMetricCount(); + int getDomainsQueried(); + } diff --git a/src/test/java/org/datadog/jmxfetch/StatusTest.java b/src/test/java/org/datadog/jmxfetch/StatusTest.java index 471aac120..eeda2bce3 100644 --- a/src/test/java/org/datadog/jmxfetch/StatusTest.java +++ b/src/test/java/org/datadog/jmxfetch/StatusTest.java @@ -33,10 +33,14 @@ public void TestStatus() throws IOException { int fakeBeansFetched = 11; int fakeMetricCount = 29; int fakeAttributeCount = 55; + int fakeDomainsQueried = 3; + double fakeBeansAttributeMatchRatio = .4; instance.setBeansFetched(fakeBeansFetched); instance.setMetricCount(fakeMetricCount); instance.setTopLevelAttributeCount(fakeAttributeCount); + instance.setDomainsQueried(fakeDomainsQueried); + instance.setAttributeMatchRatio(fakeBeansAttributeMatchRatio); status.addInstanceStats("fake_check", "fake_instance", 10, 3, "fake_message", Status.STATUS_OK, instance); status.flush(); @@ -55,6 +59,8 @@ public void TestStatus() throws IOException { assertEquals(fakeBeansFetched, stats.get("instance_bean_count")); assertEquals(fakeAttributeCount, stats.get("instance_attribute_count")); assertEquals(fakeMetricCount, stats.get("instance_metric_count")); + assertEquals(fakeDomainsQueried, stats.get("instance_domains_queried")); + assertEquals(fakeBeansAttributeMatchRatio, stats.get("instance_attribute_match_ratio")); assertEquals("fake_message", stats.get("message")); assertEquals(Status.STATUS_OK, stats.get("status")); }