Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminate with an error if started as in agent mode but configured with a remote JMX url #673

Closed
fstab opened this issue Jan 16, 2022 · 2 comments

Comments

@fstab
Copy link
Member

fstab commented Jan 16, 2022

jmx_exporter can run in an agent mode (attaching directly to the JVM to be motitored) or in a standalone mode (connecting to a remote JVM to be monitored).

If you want to connect to a remote JVM you have to configure either the jmxUrl or the hostPort.

Here's an overview of the possible configurations:

1 Running in agent mode without configuring jmxUrl or hostPort

This is as expected, if you run jmx_exporter in agent mode you don't need to connect to a remote JVM.

2 Running in standalone mode and configuring jmxUrl or hostPort

This is as expected, if you run jmx_exporter in standalone mode you want to configure the remote connection to the JVM to be monitored.

3 Running in standalone mode without configuring jmxUrl or hostPort

This is now prevented and will result in a startup error.

private void exitIfJmxUrlMissing() {
// If the jmxUrl configuration is missing, the JmxScraper implicitly monitors the JVM it runs in.
// This is good if the JmxCollector is used in the Java agent, because the Java agent should monitor the JVM
// it is attached to.
// However, if the JmxCollector is used in the WebServer, the intention is that it monitors another process.
// If the jmxUrl configuration is missing, it should not silently ignore this and start monitoring itself.
// The WebServer sets jmxUrlRequired to true so that we can verify this and terminate with a proper error message.
if (jmxUrlRequired && config.jmxUrl.isEmpty()) {
LOGGER.severe("configuration error: one of jmxUrl or hostPort is required");
System.exit(-1);
}
}

Previously, what happened was that jmx_exporter starts and monitors its own JVM, which is very likely not what you want.

4 Running in agent mode and configuring jmxUrl or hostPort

This is currently possible. What happens is that jmx_exporter attaches to a JVM, but instead of monitoring that JVM it tries to connect to a remote JVM to monitor.

Proposal

Modify the behavior in case 4 and make jmx_exporter terminate with an error. If you run jmx_exporter in agent mode attaching to a JVM you certainly don't want to use it to monitor a remote JVM.

@dhoard
Copy link
Collaborator

dhoard commented Jan 16, 2022

I agree... case 4 doesn't seem like something we would want to support.

If a user wants to run Tomcat/Jetty (or another JEE servlet container) to monitor an external application (as opposed to the built-in HTTPServer), they really should be using client_java and MetricsServlet directly.

@dhoard
Copy link
Collaborator

dhoard commented Jul 8, 2023

Closed as resolved.

@dhoard dhoard closed this as completed Jul 8, 2023
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

No branches or pull requests

2 participants