From 08a1515cc84607a2076972358e27d55596fda055 Mon Sep 17 00:00:00 2001 From: Doug Hoard Date: Fri, 28 Jul 2023 09:41:05 -0400 Subject: [PATCH] Added code to skip RuntimeMXBean attributes SystemProperties, ClassPath, (#859) BootClassPath, and LibraryPath since the calls to get the attribute values are very expensive the values are ultimately ignored Added code to skip FlightRecorderMXBean since the calls are very expensive and the values are ultimately ignored Signed-off-by: Doug Hoard --- .../main/java/io/prometheus/jmx/JmxScraper.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java index 8c3168bd..0dde91c3 100644 --- a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java +++ b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java @@ -186,6 +186,20 @@ private void scrapeBean(MBeanServerConnection beanConn, ObjectName mBeanName) { for (Object object : attributes) { if (object instanceof Attribute) { Attribute attribute = (Attribute) object; + String attributeName = attribute.getName(); + if (mBeanName.toString().equals("java.lang:type=Runtime") + && (attributeName.equalsIgnoreCase("SystemProperties") + || attributeName.equalsIgnoreCase("ClassPath") + || attributeName.equalsIgnoreCase("BootClassPath")) + || attributeName.equalsIgnoreCase("LibraryPath")) { + // Skip attributes for the "java.lang:type=Runtime" MBean because + // getting the values is expensive and the values are ultimately ignored + continue; + } else if (mBeanName.toString().equals("jdk.management.jfr:type=FlightRecorder")) { + // Skip the FlightRecorderMXBean + continue; + } + MBeanAttributeInfo mBeanAttributeInfo = name2MBeanAttributeInfo.get(attribute.getName()); logScrape(mBeanName, mBeanAttributeInfo, "process"); processBeanValue(