Skip to content

Conversation

@SylvainJuge
Copy link
Contributor

@SylvainJuge SylvainJuge commented Sep 5, 2024

When trying to reuse JMX Insight implementation in contrib (open-telemetry/opentelemetry-java-contrib#1445), the current implementation assumes that only local instances of MBeanServer are used, so we need to enable reusing it for remote connections.

Fortunately as MBeanServer (1) extends MBeanServerConnection (2), this mostly requires to replace (1) with (2).

PR initially opened as draft and does not need review for now until we have validated it works as we expect for remote connections with related PR.


For example, for a JVM configured with JMX to listen on localhost:9999 with the following JVM arguments:

-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

The following example code allows to capture metrics from this JVM (at least for metric registration, proper end-to-end testing will be required on consumer side).


JmxMetricInsight service = JmxMetricInsight.createService(GlobalOpenTelemetry.get(), 1000);

MetricConfiguration conf = new MetricConfiguration();

try (InputStream inputStream = Files.newInputStream(Paths.get("path/to/yaml.config"))) {
  JmxConfig config = RuleParser.get().loadConfig(inputStream);
  assertThat(config).isNotNull();

  List<JmxRule> defs = config.getRules();
  for (JmxRule rule : defs) {
    conf.addMetricDef(rule.buildMetricDef());
  }
}

service.startRemote(
    conf,
    () -> {
      try {
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:9999/jmxrmi");
        JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
        return Collections.singletonList(jmxc.getMBeanServerConnection());
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    });

@SylvainJuge
Copy link
Contributor Author

@robsunday this will be required in order to be able to use remote JMX connections.

@SylvainJuge
Copy link
Contributor Author

I've marked the PR as "ready for review" as it's working with the provided code example, so it should be quite straightforward to extend this to support other remote connection variants with certificates and authentication.

@SylvainJuge SylvainJuge marked this pull request as ready for review September 5, 2024 16:54
@SylvainJuge SylvainJuge requested a review from a team September 5, 2024 16:54
@SylvainJuge
Copy link
Contributor Author

@PeterF778 your input might be welcome on this JMX related PR too.

Copy link
Contributor

@PeterF778 PeterF778 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for doing this.

@trask trask merged commit 2d5775a into open-telemetry:main Sep 13, 2024
55 checks passed
@SylvainJuge SylvainJuge deleted the jmx-connection branch September 16, 2024 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants