private void addJmxMetricRegistration()

in apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetricTracker.java [419:465]


    private void addJmxMetricRegistration(JmxMetric jmxMetric, List<JmxMetricRegistration> registrations, ObjectName objectName, Object value, JmxMetric.Attribute attribute, String attributeName, @Nullable String metricPrepend) throws AttributeNotFoundException {
        String effectiveAttributeName = metricPrepend == null ? attributeName : metricPrepend + attributeName;
        boolean unsubscribeOnError = jmxConfiguration.getFaildRetryInterval().isDefault();
        if (value instanceof Number) {
            logger.debug("Found number attribute {}={}", attribute.getJmxAttributeName(), value);
            registrations.add(
                new JmxMetricRegistration(
                    attribute.getMetricName(
                        effectiveAttributeName
                    ),
                    attribute.getLabels(objectName),
                    attributeName,
                    null,
                    objectName,
                    unsubscribeOnError
                )
            );
        } else if (value instanceof CompositeData) {
            final CompositeData compositeValue = (CompositeData) value;
            for (final String key : compositeValue.getCompositeType().keySet()) {
                Object entryValue = compositeValue.get(key);
                if (entryValue instanceof Number) {
                    logger.debug("Found composite number attribute {}.{}={}", attribute.getJmxAttributeName(), key, value);
                    registrations.add(
                        new JmxMetricRegistration(
                            attribute.getCompositeMetricName(
                                key,
                                effectiveAttributeName),
                            attribute.getLabels(objectName),
                            attributeName,
                            key,
                            objectName,
                            unsubscribeOnError
                        )
                    );
                } else {
                    if (!isWildcard(attribute)) {
                        logger.warn("Can't create metric '{}' because composite value '{}' is not a number: '{}'", jmxMetric, key, entryValue);
                    }
                }
            }
        } else {
            if (!isWildcard(attribute)) {
                logger.warn("Can't create metric '{}' because attribute '{}' is not a number: '{}'", jmxMetric, attributeName, value);
            }
        }
    }