Skip to content

Commit

Permalink
Process JMX beans with an ArrayList value by returning the size of th…
Browse files Browse the repository at this point in the history
…e list

Signed-off-by: Stephen Darlington <stephen.darlington@gridgain.com>
  • Loading branch information
sdarlington committed Feb 4, 2021
1 parent f983cd5 commit 3f1ef99
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions collector/src/main/java/io/prometheus/jmx/JmxScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@
import javax.rmi.ssl.SslRMIClientSocketFactory;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -157,28 +150,22 @@ private void scrapeBean(MBeanServerConnection beanConn, ObjectName mbeanName) {
logScrape(mbeanName, name2AttrInfo.keySet(), "Fail: " + e);
return;
}
try {
for (Object attributeObj : attributes.asList()) {
if (Attribute.class.isInstance(attributeObj)) {
Attribute attribute = (Attribute)(attributeObj);
MBeanAttributeInfo attr = name2AttrInfo.get(attribute.getName());
logScrape(mbeanName, attr, "process");
processBeanValue(
mbeanName.getDomain(),
jmxMBeanPropertyCache.getKeyPropertyList(mbeanName),
new LinkedList<String>(),
attr.getName(),
attr.getType(),
attr.getDescription(),
attribute.getValue()
);
}
for (Object attributeObj : attributes) {
if (Attribute.class.isInstance(attributeObj)) {
Attribute attribute = (Attribute)(attributeObj);
MBeanAttributeInfo attr = name2AttrInfo.get(attribute.getName());
logScrape(mbeanName, attr, "process");
processBeanValue(
mbeanName.getDomain(),
jmxMBeanPropertyCache.getKeyPropertyList(mbeanName),
new LinkedList<String>(),
attr.getName(),
attr.getType(),
attr.getDescription(),
attribute.getValue()
);
}
}
catch (Exception e) {
logScrape(mbeanName.toString(), "failed to process attribute");
return;
}
}


Expand Down Expand Up @@ -288,6 +275,18 @@ private void processBeanValue(
}
} else if (value.getClass().isArray()) {
logScrape(domain, "arrays are unsupported");
} else if (value instanceof ArrayList<?>) {
// We can't output a list of values here, so instead let's send the count of entries
ArrayList<?> list = (ArrayList<?>)value;
logScrape(domain + beanProperties + attrName, String.valueOf(list.size()));
this.receiver.recordBean(
domain,
beanProperties,
attrKeys,
attrName,
attrType,
attrDescription,
list.size());
} else {
logScrape(domain + beanProperties, attrType + " is not exported");
}
Expand Down

0 comments on commit 3f1ef99

Please sign in to comment.