From f983cd572d71cc9d8e764af911812a1f7179b6c7 Mon Sep 17 00:00:00 2001 From: Stephen Darlington Date: Wed, 13 Jan 2021 17:19:40 +0000 Subject: [PATCH 1/2] Catch exception so exporter works on Ignite 2.8+ Signed-off-by: Stephen Darlington --- .../java/io/prometheus/jmx/JmxScraper.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java index d2e0add3..adc59c6c 100644 --- a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java +++ b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java @@ -157,22 +157,28 @@ private void scrapeBean(MBeanServerConnection beanConn, ObjectName mbeanName) { logScrape(mbeanName, name2AttrInfo.keySet(), "Fail: " + e); return; } - 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(), - attr.getName(), - attr.getType(), - attr.getDescription(), - attribute.getValue() - ); + 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(), + attr.getName(), + attr.getType(), + attr.getDescription(), + attribute.getValue() + ); + } } } + catch (Exception e) { + logScrape(mbeanName.toString(), "failed to process attribute"); + return; + } } From 3f1ef99b28ef307618610988e89cbb4f3513cc4f Mon Sep 17 00:00:00 2001 From: Stephen Darlington Date: Thu, 4 Feb 2021 13:53:22 +0000 Subject: [PATCH 2/2] Process JMX beans with an ArrayList value by returning the size of the list Signed-off-by: Stephen Darlington --- .../java/io/prometheus/jmx/JmxScraper.java | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java index adc59c6c..c487d4c0 100644 --- a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java +++ b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java @@ -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; @@ -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(), - 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(), + attr.getName(), + attr.getType(), + attr.getDescription(), + attribute.getValue() + ); } } - catch (Exception e) { - logScrape(mbeanName.toString(), "failed to process attribute"); - return; - } } @@ -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"); }