From df470802e2b08cb60997085eaeb93ebb9f4036fe Mon Sep 17 00:00:00 2001 From: Doug Hoard Date: Wed, 26 Jul 2023 23:15:14 -0400 Subject: [PATCH] Added code to skip RuntimeMXBean attributes SystemProperties, ClassPath, 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 aa713213..d50fc3fb 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(