Skip to content

Commit

Permalink
add bean attribute instance stats
Browse files Browse the repository at this point in the history
  • Loading branch information
rayz committed Oct 18, 2023
1 parent 93e6f90 commit 02ca784
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/datadog/jmxfetch/Configuration.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,6 +11,7 @@
import java.util.Map.Entry;
import java.util.Set;


public class Configuration {

private Map<String, Object> conf;
Expand Down Expand Up @@ -194,7 +197,6 @@ private static Map<String, Map<String, String>> getCommonScopeByDomain(
}
commonScopeByDomain.put(domainName, commonScope);
}

return commonScopeByDomain;
}

Expand Down Expand Up @@ -231,8 +233,7 @@ private static String beanScopeToString(
* @param configurationList the configuration list to process
* @return common bean pattern strings
*/
public static List<String> getGreatestCommonScopes(
List<Configuration> configurationList) {
public static List<String> getGreatestCommonScopes(List<Configuration> configurationList) {
List<Configuration> includeConfigList =
getIncludeConfigurationList(configurationList);
Map<String, List<Filter>> includeFiltersByDomain =
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 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,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);
Expand Down
16 changes: 16 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,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() {
Expand All @@ -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;
Expand All @@ -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;
}

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

int getMetricCount();

int getDomainsQueried();

}
6 changes: 6 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,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();
Expand All @@ -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"));
}
Expand Down

0 comments on commit 02ca784

Please sign in to comment.