From bb80b303dd71e699df23d5f7ffb736ff4a64bcd3 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 2 Mar 2022 20:43:13 -0800 Subject: [PATCH] More JMX debug logging --- .../perfcounter/AvailableJmxMetricLogger.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/perfcounter/AvailableJmxMetricLogger.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/perfcounter/AvailableJmxMetricLogger.java index c5291ff0058..b80e2e5c6b0 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/perfcounter/AvailableJmxMetricLogger.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/perfcounter/AvailableJmxMetricLogger.java @@ -23,11 +23,11 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; +import static java.util.Collections.singleton; import static java.util.Collections.singletonList; import java.lang.management.ManagementFactory; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -119,31 +119,33 @@ private static Map> getAvailableJmxAttributes() { Map> availableJmxMetrics = new HashMap<>(); for (ObjectName objectName : objectNames) { String name = objectName.toString(); + Set attrs; try { - Set attrs = getJmxAttributes(server, objectName); - if (!attrs.isEmpty()) { - availableJmxMetrics.put(name, attrs); + attrs = getNumericAttributeNames(server, objectName); + if (attrs.isEmpty()) { + attrs.add(""); } } catch (Exception e) { + attrs = singleton(" getJmxAttributes(MBeanServer server, ObjectName objectName) + private static Set getNumericAttributeNames(MBeanServer server, ObjectName objectName) throws Exception { MBeanInfo mbeanInfo = server.getMBeanInfo(objectName); - Set attributeNames = new HashSet<>(); + Set numericAttributeNames = new HashSet<>(); for (MBeanAttributeInfo attribute : mbeanInfo.getAttributes()) { if (attribute.isReadable()) { try { Object value = server.getAttribute(objectName, attribute.getName()); - attributeNames.addAll(getNumericAttributes(attribute, value)); + numericAttributeNames.addAll(getNumericAttributeNames(attribute, value)); } catch (Exception e) { // log exception at trace level since this is expected in several cases, e.g. // "java.lang.UnsupportedOperationException: CollectionUsage threshold is not supported" @@ -152,10 +154,10 @@ private static Set getJmxAttributes(MBeanServer server, ObjectName objec } } } - return attributeNames; + return numericAttributeNames; } - private static List getNumericAttributes(MBeanAttributeInfo attribute, Object value) { + private static List getNumericAttributeNames(MBeanAttributeInfo attribute, Object value) { String attributeType = attribute.getType(); if (NUMERIC_ATTRIBUTE_TYPES.contains(attributeType) && value instanceof Number) { return singletonList(attribute.getName());