diff --git a/instrumentation/runtime-metrics/library/README.md b/instrumentation/jmx/javaagent/README.md similarity index 100% rename from instrumentation/runtime-metrics/library/README.md rename to instrumentation/jmx/javaagent/README.md diff --git a/instrumentation/runtime-metrics/library/activemq.md b/instrumentation/jmx/javaagent/activemq.md similarity index 100% rename from instrumentation/runtime-metrics/library/activemq.md rename to instrumentation/jmx/javaagent/activemq.md diff --git a/instrumentation/jmx/javaagent/build.gradle.kts b/instrumentation/jmx/javaagent/build.gradle.kts new file mode 100644 index 000000000000..0804b9a57cfe --- /dev/null +++ b/instrumentation/jmx/javaagent/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("otel.javaagent-instrumentation") +} + +dependencies { + implementation(project(":instrumentation:jmx:jmx-engine:library")) + implementation(project(":instrumentation:jmx:jmx-yaml:library")) + + compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure") +} diff --git a/instrumentation/runtime-metrics/library/hadoop.md b/instrumentation/jmx/javaagent/hadoop.md similarity index 100% rename from instrumentation/runtime-metrics/library/hadoop.md rename to instrumentation/jmx/javaagent/hadoop.md diff --git a/instrumentation/runtime-metrics/library/jetty.md b/instrumentation/jmx/javaagent/jetty.md similarity index 91% rename from instrumentation/runtime-metrics/library/jetty.md rename to instrumentation/jmx/javaagent/jetty.md index 646edaea29aa..e04622a17918 100644 --- a/instrumentation/runtime-metrics/library/jetty.md +++ b/instrumentation/jmx/javaagent/jetty.md @@ -5,8 +5,8 @@ Here is the list of metrics based on MBeans exposed by Jetty. | Metric Name | Type | Attributes | Description | |--------------------------------|---------------|--------------|------------------------------------------------------| | jetty.session.sessionsCreated | Counter | resource | The number of sessions established in total | -| jetty.session.sessionTimeTotal | UpDownCounter | resource | The total time sessions have been active | -| jetty.session.sessionTimeMax | UpDownCounter | resource | The maximum amount of time a session has been active | +| jetty.session.sessionTimeTotal | Counter | resource | The total time sessions have been active | +| jetty.session.sessionTimeMax | Gauge | resource | The maximum amount of time a session has been active | | jetty.session.sessionTimeMean | Gauge | resource | The mean time sessions remain active | | jetty.threads.busyThreads | UpDownCounter | | The current number of busy threads | | jetty.threads.idleThreads | UpDownCounter | | The current number of idle threads | diff --git a/instrumentation/runtime-metrics/library/kafka-broker.md b/instrumentation/jmx/javaagent/kafka-broker.md similarity index 98% rename from instrumentation/runtime-metrics/library/kafka-broker.md rename to instrumentation/jmx/javaagent/kafka-broker.md index beac186a4f1e..2dddfbb19d82 100644 --- a/instrumentation/runtime-metrics/library/kafka-broker.md +++ b/instrumentation/jmx/javaagent/kafka-broker.md @@ -18,7 +18,7 @@ Broker metrics: | kafka.partition.offline | UpDownCounter | | The number of partitions offline | | kafka.partition.underReplicated | UpDownCounter | | The number of under replicated partitions | | kafka.isr.operation.count | UpDownCounter | operation | The number of in-sync replica shrink and expand operations | -| kafka.lag.max | Counter | | The max lag in messages between follower and leader replicas | +| kafka.lag.max | Gauge | | The max lag in messages between follower and leader replicas | | kafka.controller.active.count | UpDownCounter | | The number of controllers active on the broker | | kafka.leaderElection.count | Counter | | The leader election count | | kafka.leaderElection.unclean.count | Counter | | Unclean leader election count - increasing indicates broker failures | diff --git a/instrumentation/runtime-metrics/library/kafka-consumer.md b/instrumentation/jmx/javaagent/kafka-consumer.md similarity index 100% rename from instrumentation/runtime-metrics/library/kafka-consumer.md rename to instrumentation/jmx/javaagent/kafka-consumer.md diff --git a/instrumentation/runtime-metrics/library/kafka-producer.md b/instrumentation/jmx/javaagent/kafka-producer.md similarity index 100% rename from instrumentation/runtime-metrics/library/kafka-producer.md rename to instrumentation/jmx/javaagent/kafka-producer.md diff --git a/instrumentation/jmx/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java b/instrumentation/jmx/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java new file mode 100644 index 000000000000..6b365c6bffb4 --- /dev/null +++ b/instrumentation/jmx/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java @@ -0,0 +1,89 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.javaagent.jmx; + +import static java.util.logging.Level.CONFIG; +import static java.util.logging.Level.FINE; + +import com.google.auto.service.AutoService; +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.instrumentation.jmx.engine.JmxMetricInsight; +import io.opentelemetry.instrumentation.jmx.engine.MetricConfiguration; +import io.opentelemetry.instrumentation.jmx.yaml.RuleParser; +import io.opentelemetry.javaagent.extension.AgentListener; +import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import java.io.File; +import java.io.InputStream; +import java.nio.file.Files; + +/** An {@link AgentListener} that enables JMX metrics during agent startup. */ +@AutoService(AgentListener.class) +public class JmxMetricInsightInstaller implements AgentListener { + + @Override + public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredSdk) { + ConfigProperties config = autoConfiguredSdk.getConfig(); + + if (config.getBoolean("otel.jmx.enabled", true)) { + JmxMetricInsight service = JmxMetricInsight.createService(GlobalOpenTelemetry.get(), config); + MetricConfiguration conf = buildMetricConfiguration(); + service.start(conf); + } + } + + private static String resourceFor(String platform) { + return "/jmx/rules/" + platform + ".yaml"; + } + + private static void addRulesForPlatform(String platform, MetricConfiguration conf) { + String yamlResource = resourceFor(platform); + try (InputStream inputStream = + JmxMetricInsightInstaller.class.getResourceAsStream(yamlResource)) { + if (inputStream != null) { + JmxMetricInsight.getLogger().log(FINE, "Opened input stream {0}", yamlResource); + RuleParser parserInstance = RuleParser.get(); + parserInstance.addMetricDefs(conf, inputStream); + } else { + JmxMetricInsight.getLogger().log(CONFIG, "No support found for {0}", platform); + } + } catch (Exception e) { + JmxMetricInsight.getLogger().warning(e.getMessage()); + } + } + + private static void buildFromDefaultRules(MetricConfiguration conf) { + String targetSystem = System.getProperty("otel.jmx.target.system", "").trim(); + String[] platforms = targetSystem.length() == 0 ? new String[0] : targetSystem.split(","); + + for (String platform : platforms) { + addRulesForPlatform(platform, conf); + } + } + + private static void buildFromUserRules(MetricConfiguration conf) { + String jmxDir = System.getProperty("otel.jmx.config"); + if (jmxDir != null) { + JmxMetricInsight.getLogger().log(CONFIG, "JMX config file name: {0}", jmxDir); + RuleParser parserInstance = RuleParser.get(); + try (InputStream inputStream = Files.newInputStream(new File(jmxDir.trim()).toPath())) { + parserInstance.addMetricDefs(conf, inputStream); + } catch (Exception e) { + JmxMetricInsight.getLogger().warning(e.getMessage()); + } + } + } + + private static MetricConfiguration buildMetricConfiguration() { + MetricConfiguration conf = new MetricConfiguration(); + + buildFromDefaultRules(conf); + + buildFromUserRules(conf); + + return conf; + } +} diff --git a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/activemq.yaml b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/activemq.yaml similarity index 100% rename from instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/activemq.yaml rename to instrumentation/jmx/javaagent/src/main/resources/jmx/rules/activemq.yaml diff --git a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/hadoop.yaml b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/hadoop.yaml similarity index 100% rename from instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/hadoop.yaml rename to instrumentation/jmx/javaagent/src/main/resources/jmx/rules/hadoop.yaml diff --git a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/jetty.yaml b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/jetty.yaml similarity index 93% rename from instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/jetty.yaml rename to instrumentation/jmx/javaagent/src/main/resources/jmx/rules/jetty.yaml index d387a2d16a8e..610c37ea3f48 100644 --- a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/jetty.yaml +++ b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/jetty.yaml @@ -13,8 +13,10 @@ rules: type: counter desc: The number of sessions established in total sessionTimeTotal: + type: counter desc: The total time sessions have been active sessionTimeMax: + type: gauge desc: The maximum amount of time a session has been active sessionTimeMean: type: gauge @@ -51,4 +53,4 @@ rules: LoggerCount: type: updowncounter unit: 1 - desc: The number of registered loggers by name \ No newline at end of file + desc: The number of registered loggers by name diff --git a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/kafka-broker.yaml b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/kafka-broker.yaml similarity index 99% rename from instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/kafka-broker.yaml rename to instrumentation/jmx/javaagent/src/main/resources/jmx/rules/kafka-broker.yaml index 584c90d2db29..f85c58a999e1 100644 --- a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/kafka-broker.yaml +++ b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/kafka-broker.yaml @@ -159,7 +159,6 @@ rules: mapping: Value: metric: kafka.lag.max - type: counter desc: The max lag in messages between follower and leader replicas unit: '{messages}' diff --git a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/kafka-consumer.yaml b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/kafka-consumer.yaml similarity index 100% rename from instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/kafka-consumer.yaml rename to instrumentation/jmx/javaagent/src/main/resources/jmx/rules/kafka-consumer.yaml diff --git a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/kafka-producer.yaml b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/kafka-producer.yaml similarity index 100% rename from instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/kafka-producer.yaml rename to instrumentation/jmx/javaagent/src/main/resources/jmx/rules/kafka-producer.yaml diff --git a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/tomcat.yaml b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/tomcat.yaml similarity index 100% rename from instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/tomcat.yaml rename to instrumentation/jmx/javaagent/src/main/resources/jmx/rules/tomcat.yaml diff --git a/instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/wildfly.yaml b/instrumentation/jmx/javaagent/src/main/resources/jmx/rules/wildfly.yaml similarity index 100% rename from instrumentation/runtime-metrics/library/src/main/resources/jmx/rules/wildfly.yaml rename to instrumentation/jmx/javaagent/src/main/resources/jmx/rules/wildfly.yaml diff --git a/instrumentation/runtime-metrics/library/tomcat.md b/instrumentation/jmx/javaagent/tomcat.md similarity index 100% rename from instrumentation/runtime-metrics/library/tomcat.md rename to instrumentation/jmx/javaagent/tomcat.md diff --git a/instrumentation/runtime-metrics/library/wildfly.md b/instrumentation/jmx/javaagent/wildfly.md similarity index 100% rename from instrumentation/runtime-metrics/library/wildfly.md rename to instrumentation/jmx/javaagent/wildfly.md diff --git a/instrumentation/jmx/jmx-engine/library/build.gradle.kts b/instrumentation/jmx/jmx-engine/library/build.gradle.kts new file mode 100644 index 000000000000..399a2611f59b --- /dev/null +++ b/instrumentation/jmx/jmx-engine/library/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("otel.library-instrumentation") +} + +dependencies { + + compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure") + + testImplementation(project(":testing-common")) +} diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/AttributeInfo.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/AttributeInfo.java similarity index 95% rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/AttributeInfo.java rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/AttributeInfo.java index 39990a75ee56..01b68bb13869 100644 --- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/AttributeInfo.java +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/AttributeInfo.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.runtimemetrics.jmx; +package io.opentelemetry.instrumentation.jmx.engine; /** * A class holding relevant information about an MBean attribute which will be used for collecting diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/AttributeValueExtractor.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/AttributeValueExtractor.java similarity index 93% rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/AttributeValueExtractor.java rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/AttributeValueExtractor.java index d526d8d634e7..24a6ad35176b 100644 --- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/AttributeValueExtractor.java +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/AttributeValueExtractor.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.runtimemetrics.jmx; +package io.opentelemetry.instrumentation.jmx.engine; import static java.util.logging.Level.FINE; import static java.util.logging.Level.INFO; @@ -23,6 +23,9 @@ * immutable. */ public class AttributeValueExtractor implements LabelExtractor { + + private static final Logger logger = Logger.getLogger(AttributeValueExtractor.class.getName()); + // The attribute name to be used during value extraction from MBean private final String baseName; @@ -95,9 +98,8 @@ String getAttributeName() { * @return AttributeInfo if the attribute is properly recognized, or null */ AttributeInfo getAttributeInfo(MBeanServer server, ObjectName objectName) { - if (MetricService.logger.isLoggable(FINE)) { - MetricService.logger.log( - FINE, "Resolving {0} for {1}", new Object[] {getAttributeName(), objectName}); + if (logger.isLoggable(FINE)) { + logger.log(FINE, "Resolving {0} for {1}", new Object[] {getAttributeName(), objectName}); } try { @@ -119,8 +121,8 @@ AttributeInfo getAttributeInfo(MBeanServer server, ObjectName objectName) { // It is fairly normal to get null values, especially during startup, // but it is much more suspicious to get non-numbers Level logLevel = sampleValue == null ? FINE : INFO; - if (MetricService.logger.isLoggable(logLevel)) { - MetricService.logger.log( + if (logger.isLoggable(logLevel)) { + logger.log( logLevel, "Unusable value {0} for attribute {1} and ObjectName {2}", new Object[] { @@ -134,8 +136,8 @@ AttributeInfo getAttributeInfo(MBeanServer server, ObjectName objectName) { } } - if (MetricService.logger.isLoggable(FINE)) { - MetricService.logger.log( + if (logger.isLoggable(FINE)) { + logger.log( FINE, "Cannot find attribute {0} for ObjectName {1}", new Object[] {baseName, objectName}); @@ -143,9 +145,9 @@ AttributeInfo getAttributeInfo(MBeanServer server, ObjectName objectName) { } catch (InstanceNotFoundException e) { // Should not happen. The ObjectName we use has been provided by the MBeanServer we use. - MetricService.logger.log(INFO, "The MBeanServer does not find {0}", objectName); + logger.log(INFO, "The MBeanServer does not find {0}", objectName); } catch (Exception e) { - MetricService.logger.log( + logger.log( FINE, "Exception {0} while inspecting attributes for ObjectName {1}", new Object[] {e, objectName}); diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/BeanFinder.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanFinder.java similarity index 98% rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/BeanFinder.java rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanFinder.java index d0f769a0efe0..19e28429e860 100644 --- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/BeanFinder.java +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanFinder.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.runtimemetrics.jmx; +package io.opentelemetry.instrumentation.jmx.engine; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import java.util.ArrayList; diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/BeanPack.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanPack.java similarity index 91% rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/BeanPack.java rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanPack.java index 3bbd7d03c1a9..d0b2143712c8 100644 --- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/BeanPack.java +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanPack.java @@ -3,14 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.runtimemetrics.jmx; +package io.opentelemetry.instrumentation.jmx.engine; import javax.management.ObjectName; import javax.management.QueryExp; /** * A class describing a set of MBeans which can be used to collect values for a metric. Objects of - * this class are inmutable. + * this class are immutable. */ public class BeanPack { // How to specify the MBean(s) diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/DetectionStatus.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/DetectionStatus.java similarity index 88% rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/DetectionStatus.java rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/DetectionStatus.java index 40a78a440b00..e012295fda19 100644 --- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/DetectionStatus.java +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/DetectionStatus.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.runtimemetrics.jmx; +package io.opentelemetry.instrumentation.jmx.engine; import java.util.Collection; import javax.management.MBeanServer; @@ -11,7 +11,7 @@ /** * A class encapsulating a set of ObjectNames and the MBeanServer that recognized them. Objects of - * this class are inmutable. + * this class are immutable. */ class DetectionStatus { diff --git a/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/JmxMetricInsight.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/JmxMetricInsight.java new file mode 100644 index 000000000000..2f5a513eb156 --- /dev/null +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/JmxMetricInsight.java @@ -0,0 +1,49 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jmx.engine; + +import static java.util.logging.Level.CONFIG; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import java.util.logging.Logger; + +/** Collecting and exporting JMX metrics. */ +public class JmxMetricInsight { + + private static final Logger logger = Logger.getLogger(JmxMetricInsight.class.getName()); + + private static final String INSTRUMENTATION_SCOPE = "io.opentelemetry.jmx"; + + private final OpenTelemetry openTelemetry; + private final ConfigProperties configProperties; + + public static JmxMetricInsight createService(OpenTelemetry ot, ConfigProperties config) { + return new JmxMetricInsight(ot, config); + } + + public static Logger getLogger() { + return logger; + } + + private JmxMetricInsight(OpenTelemetry ot, ConfigProperties config) { + openTelemetry = ot; + configProperties = config; + } + + public void start(MetricConfiguration conf) { + if (conf.isEmpty()) { + logger.log( + CONFIG, + "Empty JMX configuration, no metrics will be collected for InstrumentationScope " + + INSTRUMENTATION_SCOPE); + } else { + MetricRegistrar registrar = new MetricRegistrar(openTelemetry, INSTRUMENTATION_SCOPE); + BeanFinder finder = new BeanFinder(registrar, configProperties); + finder.discoverBeans(conf); + } + } +} diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/LabelExtractor.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/LabelExtractor.java similarity index 86% rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/LabelExtractor.java rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/LabelExtractor.java index 967573fa42bd..b31666853b48 100644 --- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/LabelExtractor.java +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/LabelExtractor.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.runtimemetrics.jmx; +package io.opentelemetry.instrumentation.jmx.engine; import javax.management.MBeanServer; import javax.management.ObjectName; diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricBanner.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricBanner.java similarity index 92% rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricBanner.java rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricBanner.java index 2c74088729da..57b5c41c421d 100644 --- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricBanner.java +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricBanner.java @@ -3,13 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.runtimemetrics.jmx; +package io.opentelemetry.instrumentation.jmx.engine; /** * A class providing the user visible characteristics (name, type, description and units) of a * metric to be reported with OpenTelemetry. * - *
Objects of this class are inmutable. + *
Objects of this class are immutable. */ public class MetricBanner { diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricConfiguration.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricConfiguration.java similarity index 90% rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricConfiguration.java rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricConfiguration.java index f1c8c8afc2f6..dee55e6b2ba0 100644 --- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricConfiguration.java +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricConfiguration.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.runtimemetrics.jmx; +package io.opentelemetry.instrumentation.jmx.engine; import java.util.ArrayList; import java.util.Collection; diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricDef.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricDef.java similarity index 92% rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricDef.java rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricDef.java index 1380deb32576..3d812a0bc513 100644 --- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricDef.java +++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricDef.java @@ -3,12 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.runtimemetrics.jmx; +package io.opentelemetry.instrumentation.jmx.engine; /** * A class providing a complete definition on how to create an Open Telemetry metric out of the JMX * system: how to extract values from MBeans and how to model, name and label them using - * OpenTelemetry Metric API. Objects of this class are inmutable. + * OpenTelemetry Metric API. Objects of this class are immutable. * *
Example: The JVM provides an MBean with ObjectName "java.lang:type=Threading", and one of the
* MBean attributes is "ThreadCount". This MBean can be used to provide a metric showing the current
diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricExtractor.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricExtractor.java
similarity index 95%
rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricExtractor.java
rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricExtractor.java
index 70ae816e9474..0b43df732b00 100644
--- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricExtractor.java
+++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricExtractor.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.runtimemetrics.jmx;
+package io.opentelemetry.instrumentation.jmx.engine;
/**
* A class holding the info needed to support a single metric: how to define it in OpenTelemetry and
diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricLabel.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricLabel.java
similarity index 92%
rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricLabel.java
rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricLabel.java
index 1cce4a01eb6b..27083ce104cc 100644
--- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricLabel.java
+++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricLabel.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.runtimemetrics.jmx;
+package io.opentelemetry.instrumentation.jmx.engine;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -11,7 +11,7 @@
/**
* A class representing a metric attribute (label). It is responsible for extracting a label value
* (to be reported as a Measurement attribute), and for holding the corresponding label name to be
- * used. Objects of this class are inmutable.
+ * used. Objects of this class are immutable.
*/
public class MetricLabel {
private final String labelName;
diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricRegistrar.java b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricRegistrar.java
similarity index 94%
rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricRegistrar.java
rename to instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricRegistrar.java
index 461839b4de75..d67e1256f1f1 100644
--- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/MetricRegistrar.java
+++ b/instrumentation/jmx/jmx-engine/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricRegistrar.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.runtimemetrics.jmx;
+package io.opentelemetry.instrumentation.jmx.engine;
import static java.util.logging.Level.CONFIG;
@@ -18,12 +18,15 @@
import io.opentelemetry.api.metrics.ObservableLongMeasurement;
import java.util.Collection;
import java.util.function.Consumer;
+import java.util.logging.Logger;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/** A class responsible for maintaining the set of metrics to collect and report. */
class MetricRegistrar {
+ private static final Logger logger = Logger.getLogger(MetricRegistrar.class.getName());
+
private final Meter meter;
MetricRegistrar(OpenTelemetry openTelemetry, String instrumentationScope) {
@@ -80,7 +83,7 @@ void enrollExtractor(
} else {
builder.buildWithCallback(longTypeCallback(extractor));
}
- MetricService.logger.log(CONFIG, "Created Counter for {0}", metricName);
+ logger.log(CONFIG, "Created Counter for {0}", metricName);
}
break;
@@ -101,7 +104,7 @@ void enrollExtractor(
} else {
builder.buildWithCallback(longTypeCallback(extractor));
}
- MetricService.logger.log(CONFIG, "Created UpDownCounter for {0}", metricName);
+ logger.log(CONFIG, "Created UpDownCounter for {0}", metricName);
}
break;
@@ -122,7 +125,7 @@ void enrollExtractor(
} else {
builder.ofLongs().buildWithCallback(longTypeCallback(extractor));
}
- MetricService.logger.log(CONFIG, "Created Gauge for {0}", metricName);
+ logger.log(CONFIG, "Created Gauge for {0}", metricName);
}
}
}
diff --git a/instrumentation/runtime-metrics/library/src/test/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/AttributeExtractorTest.java b/instrumentation/jmx/jmx-engine/library/src/test/java/io/opentelemetry/instrumentation/jmx/engine/AttributeExtractorTest.java
similarity index 99%
rename from instrumentation/runtime-metrics/library/src/test/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/AttributeExtractorTest.java
rename to instrumentation/jmx/jmx-engine/library/src/test/java/io/opentelemetry/instrumentation/jmx/engine/AttributeExtractorTest.java
index 272e7def86ef..249d9243224a 100644
--- a/instrumentation/runtime-metrics/library/src/test/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/AttributeExtractorTest.java
+++ b/instrumentation/jmx/jmx-engine/library/src/test/java/io/opentelemetry/instrumentation/jmx/engine/AttributeExtractorTest.java
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.runtimemetrics.jmx;
+package io.opentelemetry.instrumentation.jmx.engine;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/instrumentation/jmx/jmx-yaml/library/build.gradle.kts b/instrumentation/jmx/jmx-yaml/library/build.gradle.kts
new file mode 100644
index 000000000000..7dd35d0e9e8c
--- /dev/null
+++ b/instrumentation/jmx/jmx-yaml/library/build.gradle.kts
@@ -0,0 +1,10 @@
+plugins {
+ id("otel.library-instrumentation")
+}
+
+dependencies {
+ implementation("org.yaml:snakeyaml")
+ implementation(project(":instrumentation:jmx:jmx-engine:library"))
+
+ testImplementation(project(":testing-common"))
+}
diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/conf/data/JmxConfig.java b/instrumentation/jmx/jmx-yaml/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/JmxConfig.java
similarity index 83%
rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/conf/data/JmxConfig.java
rename to instrumentation/jmx/jmx-yaml/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/JmxConfig.java
index f79f9d02a609..1749a098310c 100644
--- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/conf/data/JmxConfig.java
+++ b/instrumentation/jmx/jmx-yaml/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/JmxConfig.java
@@ -3,10 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.runtimemetrics.jmx.conf.data;
+package io.opentelemetry.instrumentation.jmx.yaml;
-import io.opentelemetry.instrumentation.runtimemetrics.jmx.MetricConfiguration;
-import io.opentelemetry.instrumentation.runtimemetrics.jmx.MetricDef;
+import io.opentelemetry.instrumentation.jmx.engine.MetricConfiguration;
+import io.opentelemetry.instrumentation.jmx.engine.MetricDef;
import java.util.List;
/**
diff --git a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/conf/data/JmxRule.java b/instrumentation/jmx/jmx-yaml/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/JmxRule.java
similarity index 91%
rename from instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/conf/data/JmxRule.java
rename to instrumentation/jmx/jmx-yaml/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/JmxRule.java
index a18694c584ed..10dd9ac96731 100644
--- a/instrumentation/runtime-metrics/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/jmx/conf/data/JmxRule.java
+++ b/instrumentation/jmx/jmx-yaml/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/JmxRule.java
@@ -3,14 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.runtimemetrics.jmx.conf.data;
-
-import io.opentelemetry.instrumentation.runtimemetrics.jmx.AttributeValueExtractor;
-import io.opentelemetry.instrumentation.runtimemetrics.jmx.BeanPack;
-import io.opentelemetry.instrumentation.runtimemetrics.jmx.MetricBanner;
-import io.opentelemetry.instrumentation.runtimemetrics.jmx.MetricDef;
-import io.opentelemetry.instrumentation.runtimemetrics.jmx.MetricExtractor;
-import io.opentelemetry.instrumentation.runtimemetrics.jmx.MetricLabel;
+package io.opentelemetry.instrumentation.jmx.yaml;
+
+import io.opentelemetry.instrumentation.jmx.engine.AttributeValueExtractor;
+import io.opentelemetry.instrumentation.jmx.engine.BeanPack;
+import io.opentelemetry.instrumentation.jmx.engine.MetricBanner;
+import io.opentelemetry.instrumentation.jmx.engine.MetricDef;
+import io.opentelemetry.instrumentation.jmx.engine.MetricExtractor;
+import io.opentelemetry.instrumentation.jmx.engine.MetricLabel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -94,10 +94,10 @@ public void setMapping(Map