Skip to content

Commit

Permalink
Support jsr77 j2ee statistics (#531)
Browse files Browse the repository at this point in the history
* Support jsr77 j2ee statistics
  • Loading branch information
amarziali authored Jul 10, 2024
1 parent 66d800a commit 9030283
Show file tree
Hide file tree
Showing 15 changed files with 732 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>javax.management.j2ee</groupId>
<artifactId>javax.management.j2ee-api</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/datadog/jmxfetch/JmxComplexAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;

import org.datadog.jmxfetch.service.ServiceNameProvider;
import org.datadog.jmxfetch.util.JeeStatisticsAttributes;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -26,9 +27,12 @@ public class JmxComplexAttribute extends JmxSubAttribute {
Arrays.asList(
"javax.management.openmbean.CompositeData",
"javax.management.openmbean.CompositeDataSupport",
"javax.management.j2ee.statistics.Statistic",
"javax.management.j2ee.statistics.Stats",
"java.util.HashMap",
"java.util.Map");


private List<String> subAttributeList = new ArrayList<String>();

/** JmxComplexAttribute constructor. */
Expand Down Expand Up @@ -68,6 +72,10 @@ private void populateSubAttributeList(Object attributeValue) {
for (String key : data.keySet()) {
this.subAttributeList.add(key);
}
} else if (JeeStatisticsAttributes.isJeeStatistic(attributeValue)) {
this.subAttributeList.addAll(JeeStatisticsAttributes.attributesFor(attributeValue));
} else if (JeeStatisticsAttributes.isJeeStat(attributeValue)) {
this.subAttributeList.addAll(JeeStatisticsAttributes.getStatisticNames(attributeValue));
}
}

Expand Down Expand Up @@ -96,6 +104,10 @@ private Object getValue(String subAttribute)
} else if (value instanceof java.util.Map) {
Map<String, Object> data = (Map<String, Object>) value;
return data.get(subAttribute);
} else if (JeeStatisticsAttributes.isJeeStatistic(value)) {
return JeeStatisticsAttributes.dataFor(value, subAttribute);
} else if (JeeStatisticsAttributes.isJeeStat(value)) {
return JeeStatisticsAttributes.getStatisticDataFor(value, subAttribute);
}
throw new NumberFormatException();
}
Expand Down
Loading

0 comments on commit 9030283

Please sign in to comment.