Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JMXFetch telemetry around bean/attribute matching #487

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,19 @@ public List<Metric> getMetrics() throws IOException {
}
}
}
instanceTelemetryBean.setBeansFetched(beans.size());
instanceTelemetryBean.setTopLevelAttributeCount(matchingAttributes.size());
instanceTelemetryBean.setMetricCount(metrics.size());
log.debug("Updated jmx bean for instance: " + this.getCheckName()
+ " With beans fetched = " + instanceTelemetryBean.getBeansFetched()
+ " top attributes = " + instanceTelemetryBean.getTopLevelAttributeCount()
+ " metrics = " + instanceTelemetryBean.getMetricCount());
if (instanceTelemetryBean != null) {
instanceTelemetryBean.setBeansFetched(beans.size());
instanceTelemetryBean.setTopLevelAttributeCount(matchingAttributes.size());
instanceTelemetryBean.setMetricCount(metrics.size());
log.debug("Updated jmx bean for instance: " + this.getCheckName()
+ " With beans fetched = " + instanceTelemetryBean.getBeansFetched()
+ " top attributes = " + instanceTelemetryBean.getTopLevelAttributeCount()
+ " metrics = " + instanceTelemetryBean.getMetricCount()
+ " domains queried = " + instanceTelemetryBean.getDomainsQueried()
+ " wildcard domain query count = "
+ instanceTelemetryBean.getWildcardDomainQueryCount()
+ " bean match ratio = " + instanceTelemetryBean.getBeanMatchRatio());
}
return metrics;
}

Expand Down Expand Up @@ -547,11 +553,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)) {
Expand Down Expand Up @@ -702,7 +711,17 @@ 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.setBeanMatchRatio((double)
beansWithAttributeMatch / beans.size());
}
log.info("Found {} matching attributes", matchingAttributes.size());
}
Expand Down Expand Up @@ -733,14 +752,24 @@ private void refreshBeansList() throws IOException {
ObjectName name = new ObjectName(scope);
this.beans.addAll(connection.queryNames(name));
}
} catch (Exception e) {
if (instanceTelemetryBean != null) {
instanceTelemetryBean.setDomainsQueried(beanScopes.size());
rayz marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (MalformedObjectNameException e) {
scottopell marked this conversation as resolved.
Show resolved Hide resolved
log.error("Unable to create ObjectName", e);
} catch (IOException e) {
log.error(
"Unable to compute a common bean scope, querying all beans as a fallback",
e);
"Unable to query mbean server", e);
}
}

this.beans = (this.beans.isEmpty()) ? connection.queryNames(null) : this.beans;
if (this.beans.isEmpty()) {
this.beans = connection.queryNames(null);
if (instanceTelemetryBean != null) {
int wildcardQueryCount = instanceTelemetryBean.getWildcardDomainQueryCount();
instanceTelemetryBean.setWildcardDomainQueryCount(wildcardQueryCount + 1);
}
}
this.lastRefreshTime = System.currentTimeMillis();
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/datadog/jmxfetch/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ 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_wildcard_domain_query_count",
instanceTelemetryBean.getWildcardDomainQueryCount());
instStats.put("instance_bean_match_ratio",
instanceTelemetryBean.getBeanMatchRatio());
}
instStats.put("message", message);
instStats.put("status", status);
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/datadog/jmxfetch/util/InstanceTelemetry.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ public class InstanceTelemetry implements InstanceTelemetryMBean {
private int beansFetched;
private int topLevelAttributeCount;
private int metricCount;
private int domainsQueried;
private int wildcardDomainQueryCount;
private double beanMatchRatio;

/** Jmxfetch telemetry bean constructor. */
public InstanceTelemetry() {
beansFetched = 0;
topLevelAttributeCount = 0;
metricCount = 0;
domainsQueried = 0;
wildcardDomainQueryCount = 0;
beanMatchRatio = 0.0;
}

public int getBeansFetched() {
Expand All @@ -27,6 +33,17 @@ public int getMetricCount() {
return metricCount;
}

public int getDomainsQueried() {
return domainsQueried;
}

public int getWildcardDomainQueryCount() {
return wildcardDomainQueryCount;
}

public double getBeanMatchRatio() {
return beanMatchRatio;
}

public void setBeansFetched(int count) {
beansFetched = count;
Expand All @@ -40,5 +57,16 @@ public void setMetricCount(int count) {
metricCount = count;
}

public void setDomainsQueried(int count) {
domainsQueried = count;
}

public void setWildcardDomainQueryCount(int count) {
wildcardDomainQueryCount = count;
}

public void setBeanMatchRatio(double ratio) {
beanMatchRatio = ratio;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public interface InstanceTelemetryMBean {

int getMetricCount();

int getDomainsQueried();

}
9 changes: 9 additions & 0 deletions src/test/java/org/datadog/jmxfetch/StatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ public void TestStatus() throws IOException {
int fakeBeansFetched = 11;
int fakeMetricCount = 29;
int fakeAttributeCount = 55;
int fakeDomainsQueried = 3;
int fakeWildcardDomainQueryCount = 9;
double fakeBeanMatchRatio = .4;

instance.setBeansFetched(fakeBeansFetched);
instance.setMetricCount(fakeMetricCount);
instance.setTopLevelAttributeCount(fakeAttributeCount);
instance.setDomainsQueried(fakeDomainsQueried);
instance.setWildcardDomainQueryCount(fakeWildcardDomainQueryCount);
instance.setBeanMatchRatio(fakeBeanMatchRatio);

status.addInstanceStats("fake_check", "fake_instance", 10, 3, "fake_message", Status.STATUS_OK, instance);
status.flush();
Expand All @@ -55,6 +61,9 @@ 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(fakeWildcardDomainQueryCount, stats.get("instance_wildcard_domain_query_count"));
assertEquals(fakeBeanMatchRatio, stats.get("instance_bean_match_ratio"));
assertEquals("fake_message", stats.get("message"));
assertEquals(Status.STATUS_OK, stats.get("status"));
}
Expand Down
Loading