Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Changelog
=========
# 0.51.1 / TBC
- [FEATURE] Add support for WebSphere PMI Stats objects with subCollections [#XXX][]

# 0.51.0 / 2025-10-28
- [FEATURE] Add configuration-level dynamic tags for JMX attribute values via `dynamic_tags` [#581][]
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,27 @@ private void getMatchingAttributes() throws IOException {
cassandraAliasing,
emptyDefaultHostname,
normalizeBeanParamTags);
} else if (PmiSubCollectionAttribute.matchAttribute(
attributeType, beanName, attributeInfo, connection)) {
log.debug(
ATTRIBUTE
+ beanName
+ " : "
+ attributeInfo
+ " has attributeInfo WebSphere Stats type with "
+ "subCollections");
jmxAttribute =
new PmiSubCollectionAttribute(
attributeInfo,
beanName,
className,
instanceName,
checkName,
connection,
serviceNameProvider,
tags,
emptyDefaultHostname,
normalizeBeanParamTags);
} else if (JmxComplexAttribute.matchAttributeType(attributeType)) {
log.debug(
ATTRIBUTE
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/org/datadog/jmxfetch/JmxComplexAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ private void populateSubAttributeList(Object attributeValue) {
this.subAttributeList.addAll(JeeStatisticsAttributes.attributesFor(attributeValue));
} else if (JeeStatisticsAttributes.isJeeStat(attributeValue)) {
this.subAttributeList.addAll(JeeStatisticsAttributes.getStatisticNames(attributeValue));
} else {
log.trace("beanName {} attributeValue type {}: no match {}",
getBeanName(), attributeValue.getClass(), attributeValue);
}
}

Expand Down Expand Up @@ -136,21 +139,6 @@ public boolean match(Configuration configuration) {
return matchAttribute(configuration) && !excludeMatchAttribute(configuration);
}

private boolean matchSubAttribute(
Filter params, String subAttributeName, boolean matchOnEmpty) {
if ((params.getAttribute() instanceof Map<?, ?>)
&& ((Map<String, Object>) (params.getAttribute()))
.containsKey(subAttributeName)) {
return true;
} else if ((params.getAttribute() instanceof List<?>
&& ((List<String>) (params.getAttribute())).contains(subAttributeName))) {
return true;
} else if (params.getAttribute() == null) {
return matchOnEmpty;
}
return false;
}

private boolean matchAttribute(Configuration configuration) {
if (matchSubAttribute(configuration.getInclude(), getAttributeName(), true)) {
return true;
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/org/datadog/jmxfetch/JmxSubAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.datadog.jmxfetch.service.ServiceNameProvider;

import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -49,4 +51,80 @@ public Metric getCachedMetric(String name) {
cachedMetrics.put(name, metric);
return metric;
}

/**
* Check if a sub-attribute matches the filter parameters.
*
* @param params the filter parameters
* @param subAttributeName the sub-attribute name to check
* @param matchOnEmpty whether to match if the attribute filter is null
* @return true if the sub-attribute matches
*/
protected boolean matchSubAttribute(
Filter params, String subAttributeName, boolean matchOnEmpty) {
if ((params.getAttribute() instanceof Map<?, ?>)
&& ((Map<String, Object>) (params.getAttribute()))
.containsKey(subAttributeName)) {
return true;
} else if ((params.getAttribute() instanceof List<?>
&& ((List<String>) (params.getAttribute())).contains(subAttributeName))) {
return true;
} else if (params.getAttribute() == null) {
return matchOnEmpty;
}
return false;
}

/**
* Get the attribute configuration for a specific metric key.
*
* @param key the metric key
* @return the attribute configuration map, or null if not found
*/
protected Map<String, ?> getAttributesFor(String key) {
Filter include = getMatchingConf().getInclude();
if (include != null) {
Object includeAttribute = include.getAttribute();
if (includeAttribute instanceof Map<?, ?>) {
return (Map<String, ?>) ((Map) includeAttribute).get(key);
}
}
return null;
}

/**
* Sort and filter metrics based on limit and sort order.
*
* @param metricKey the metric key
* @param metrics the list of metrics to sort and filter
* @return the sorted and filtered list of metrics
*/
protected List<Metric> sortAndFilter(String metricKey, List<Metric> metrics) {
Map<String, ?> attributes = getAttributesFor(metricKey);
if (attributes == null || !attributes.containsKey("limit")) {
return metrics;
}
Integer limit = (Integer) attributes.get("limit");
if (metrics.size() <= limit) {
return metrics;
}
MetricComparator comp = new MetricComparator();
Collections.sort(metrics, comp);
String sort = (String) attributes.get("sort");
if (sort == null || sort.equals("desc")) {
metrics.subList(0, limit).clear();
} else {
metrics.subList(metrics.size() - limit, metrics.size()).clear();
}
return metrics;
}

/**
* Comparator for sorting metrics by value.
*/
protected static class MetricComparator implements Comparator<Metric> {
public int compare(Metric o1, Metric o2) {
return Double.compare(o1.getValue(), o2.getValue());
}
}
}
52 changes: 0 additions & 52 deletions src/main/java/org/datadog/jmxfetch/JmxTabularAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,6 @@ protected String[] getTags(String key, String subAttribute)
return tags;
}

private Map<String, ?> getAttributesFor(String key) {
Filter include = getMatchingConf().getInclude();
if (include != null) {
Object includeAttribute = include.getAttribute();
if (includeAttribute instanceof Map<?, ?>) {
return (Map<String, ?>) ((Map) includeAttribute).get(key);
}
}
return null;
}

@Override
public List<Metric> getMetrics()
throws AttributeNotFoundException, InstanceNotFoundException, MBeanException,
Expand Down Expand Up @@ -179,32 +168,6 @@ public List<Metric> getMetrics()
return metrics;
}

private List<Metric> sortAndFilter(String metricKey, List<Metric> metrics) {
Map<String, ?> attributes = getAttributesFor(metricKey);
if (!attributes.containsKey("limit")) {
return metrics;
}
Integer limit = (Integer) attributes.get("limit");
if (metrics.size() <= limit) {
return metrics;
}
MetricComparator comp = new MetricComparator();
Collections.sort(metrics, comp);
String sort = (String) attributes.get("sort");
if (sort == null || sort.equals("desc")) {
metrics.subList(0, limit).clear();
} else {
metrics.subList(metrics.size() - limit, metrics.size()).clear();
}
return metrics;
}

private class MetricComparator implements Comparator<Metric> {
public int compare(Metric o1, Metric o2) {
return Double.compare(o1.getValue(), o2.getValue());
}
}

private Object getValue(String key, String subAttribute)
throws AttributeNotFoundException, InstanceNotFoundException, MBeanException,
ReflectionException, IOException {
Expand Down Expand Up @@ -268,21 +231,6 @@ public boolean match(Configuration configuration) {
return matchAttribute(configuration); // TODO && !excludeMatchAttribute(configuration);
}

private boolean matchSubAttribute(
Filter params, String subAttributeName, boolean matchOnEmpty) {
if ((params.getAttribute() instanceof Map<?, ?>)
&& ((Map<String, Object>) (params.getAttribute()))
.containsKey(subAttributeName)) {
return true;
} else if ((params.getAttribute() instanceof List<?>
&& ((List<String>) (params.getAttribute())).contains(subAttributeName))) {
return true;
} else if (params.getAttribute() == null) {
return matchOnEmpty;
}
return false;
}

private boolean matchAttribute(Configuration configuration) {
if (matchSubAttribute(configuration.getInclude(), getAttributeName(), true)) {
return true;
Expand Down
Loading
Loading