Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process JMX beans with an ArrayList value #580

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 14 additions & 9 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,7 +150,7 @@ private void scrapeBean(MBeanServerConnection beanConn, ObjectName mbeanName) {
logScrape(mbeanName, name2AttrInfo.keySet(), "Fail: " + e);
return;
}
for (Object attributeObj : attributes.asList()) {
for (Object attributeObj : attributes) {
if (Attribute.class.isInstance(attributeObj)) {
Attribute attribute = (Attribute)(attributeObj);
MBeanAttributeInfo attr = name2AttrInfo.get(attribute.getName());
Expand Down Expand Up @@ -282,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