Skip to content

Commit 3f1ef99

Browse files
committed
Process JMX beans with an ArrayList value by returning the size of the list
Signed-off-by: Stephen Darlington <stephen.darlington@gridgain.com>
1 parent f983cd5 commit 3f1ef99

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

collector/src/main/java/io/prometheus/jmx/JmxScraper.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@
2020
import javax.rmi.ssl.SslRMIClientSocketFactory;
2121
import java.io.IOException;
2222
import java.lang.management.ManagementFactory;
23-
import java.util.HashMap;
24-
import java.util.HashSet;
25-
import java.util.LinkedHashMap;
26-
import java.util.LinkedList;
27-
import java.util.List;
28-
import java.util.Map;
29-
import java.util.Set;
30-
import java.util.TreeSet;
23+
import java.util.*;
3124
import java.util.logging.Level;
3225
import java.util.logging.Logger;
3326

@@ -157,28 +150,22 @@ private void scrapeBean(MBeanServerConnection beanConn, ObjectName mbeanName) {
157150
logScrape(mbeanName, name2AttrInfo.keySet(), "Fail: " + e);
158151
return;
159152
}
160-
try {
161-
for (Object attributeObj : attributes.asList()) {
162-
if (Attribute.class.isInstance(attributeObj)) {
163-
Attribute attribute = (Attribute)(attributeObj);
164-
MBeanAttributeInfo attr = name2AttrInfo.get(attribute.getName());
165-
logScrape(mbeanName, attr, "process");
166-
processBeanValue(
167-
mbeanName.getDomain(),
168-
jmxMBeanPropertyCache.getKeyPropertyList(mbeanName),
169-
new LinkedList<String>(),
170-
attr.getName(),
171-
attr.getType(),
172-
attr.getDescription(),
173-
attribute.getValue()
174-
);
175-
}
153+
for (Object attributeObj : attributes) {
154+
if (Attribute.class.isInstance(attributeObj)) {
155+
Attribute attribute = (Attribute)(attributeObj);
156+
MBeanAttributeInfo attr = name2AttrInfo.get(attribute.getName());
157+
logScrape(mbeanName, attr, "process");
158+
processBeanValue(
159+
mbeanName.getDomain(),
160+
jmxMBeanPropertyCache.getKeyPropertyList(mbeanName),
161+
new LinkedList<String>(),
162+
attr.getName(),
163+
attr.getType(),
164+
attr.getDescription(),
165+
attribute.getValue()
166+
);
176167
}
177168
}
178-
catch (Exception e) {
179-
logScrape(mbeanName.toString(), "failed to process attribute");
180-
return;
181-
}
182169
}
183170

184171

@@ -288,6 +275,18 @@ private void processBeanValue(
288275
}
289276
} else if (value.getClass().isArray()) {
290277
logScrape(domain, "arrays are unsupported");
278+
} else if (value instanceof ArrayList<?>) {
279+
// We can't output a list of values here, so instead let's send the count of entries
280+
ArrayList<?> list = (ArrayList<?>)value;
281+
logScrape(domain + beanProperties + attrName, String.valueOf(list.size()));
282+
this.receiver.recordBean(
283+
domain,
284+
beanProperties,
285+
attrKeys,
286+
attrName,
287+
attrType,
288+
attrDescription,
289+
list.size());
291290
} else {
292291
logScrape(domain + beanProperties, attrType + " is not exported");
293292
}

0 commit comments

Comments
 (0)