How to access Spring-boot JMX remotely -


i know spring automatically expose jmx beans. able access locally using visualvm.

however on prod how can connect remotely app using it's jmx beans? there default port or should define in addition?

thanks, ray.

by default jmx automatically accessible locally, running jconsole locally detect local java apps without port exposure.

to access app via jmx remotely have specify rmi registry port. thing know when connecting, jmx initializes on port , then establishes data connection on random high port, huge problem if have firewall in middle. ("hey sysadmins, open everything, mkay?").

to force jmx connect on same port you've established, have couple options:

option 1: command line

-dcom.sun.management.jmxremote.port=$jmx_registry_port  -dcom.sun.management.jmxremote.rmi.port=$rmi_server_port 

if you're using spring boot can put in (appname).conf file lives alongside (appname).jar deployment.

option 2: tomcat/tomee configuration

configure jmxremotelifecyclelistener:

maven jar:

    <dependency>         <groupid>org.apache.tomcat</groupid>         <artifactid>tomcat-catalina-jmx-remote</artifactid>         <version>8.5.9</version>         <type>jar</type>     </dependency> 

configure server.xml:

<listener classname="org.apache.catalina.mbeans.jmxremotelifecyclelistener"       rmiregistryportplatform="10001" rmiserverportplatform="10002" /> 

option 3: configure programmatically

@configuration public class configurermi {      @value("${jmx.rmi.host:localhost}")     private string rmihost;      @value("${jmx.rmi.port:1099}")     private integer rmiport;      @bean     public rmiregistryfactorybean rmiregistry() {         final rmiregistryfactorybean rmiregistryfactorybean = new rmiregistryfactorybean();         rmiregistryfactorybean.setport(rmiport);         rmiregistryfactorybean.setalwayscreate(true);         return rmiregistryfactorybean;     }      @bean     @dependson("rmiregistry")     public connectorserverfactorybean connectorserverfactorybean() throws exception {         final connectorserverfactorybean connectorserverfactorybean = new connectorserverfactorybean();         connectorserverfactorybean.setobjectname("connector:name=rmi");         connectorserverfactorybean.setserviceurl(string.format("service:jmx:rmi://%s:%s/jndi/rmi://%s:%s/jmxrmi", rmihost, rmiport, rmihost, rmiport));         return connectorserverfactorybean;     } } 

the trick, you'll see, serviceurl in specify both jmx:rmi host/port , jndi:rmi host/port. if specify both, won't random high "problem".


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

html - grunt SVG to webfont -

python - Specify path of savefig with pylab or matplotlib -