To enable remote jmx monitoring across firewall it is necessary to pass following JVM arguments:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=5999
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.rmi.port=5998
IMPORTANT: jmxremote.port supplies RMI registry port. JMX RMI connections objects are exposed through another, random port or through the port defined by jmxremote.rmi.port property.
ratpack default configuration contains scripts to run server with Gradle Wrapper (./gradlew run). Then there are two processes running. One is for gradle itself and the other is for ratpack application.
JMX properties have to be passed to ratpack application process. Setting them in gradlew scripts does not help. Then they apply to gradle process only.
Thanks to the discussion on ratpack forum two solutions are feasible.
Inside build.gradle file add run{} task with jvmArgs line for everyone setting.
run {
jvmArgs "-Dcom.sun.management.jmxremote"
jvmArgs "-Dcom.sun.management.jmxremote.port=5999"
jvmArgs "-Dcom.sun.management.jmxremote.local.only=false"
jvmArgs "-Dcom.sun.management.jmxremote.authenticate=false"
jvmArgs "-Dcom.sun.management.jmxremote.ssl=false"
jvmArgs "-Dcom.sun.management.jmxremote.rmi.port=5998"
}
Add new file in for example application root folder called jmx.env. Put following settings inside it:
com.sun.management.jmxremote
com.sun.management.jmxremote.port=5999
com.sun.management.jmxremote.local.only=false
com.sun.management.jmxremote.authenticate=false
com.sun.management.jmxremote.ssl=false
com.sun.management.jmxremote.rmi.port=5998
Inside build.gradle file add run{} task and read all properties from jmx.env file:
run {
Properties properties = new Properties(System.getProperties())
try {
FileInputStream inputStream = new FileInputStream("./jmx.env")
properties.load(inputStream)
System.setProperties(properties)
System.getProperties().each { prop ->
systemProperty prop.key, prop.value
}
}
catch (FileNotFoundException ex) {
println "Could not find env file"
println "This is normal in production."
}
catch (Exception e) {
e.printStackTrace()
}
}