-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code refactoring and changes, moving to own module :instrumentation:jmx.
- Loading branch information
Showing
44 changed files
with
255 additions
and
184 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
89 changes: 89 additions & 0 deletions
89
...c/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
plugins { | ||
id("otel.library-instrumentation") | ||
} | ||
|
||
dependencies { | ||
|
||
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure") | ||
|
||
testImplementation(project(":testing-common")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...e/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/JmxMetricInsight.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.