Not sure if it is a GrailsMelody or general Grails issue.
Use Case
I want to use -Dsystem_property
arguments in GrailsMelodyConfig.
Example
javamelody.'storage-directory' = System.properties['storageDir']
I would now expect Grails/Java-Melody to use whatever I pass as -DstorageDir
as its storage directory.
But System.properties['storageDir']
seems to be not present while GrailsMelodyConfig is initialized.
Steps to reproduce
Step 1. Create new grails 2.5.3 project
grails create-app where-are-my-system-properties
Step 2. Add grails-meldody dependency to BuildConfig
// […]
plugins {
// […]
compile ":grails-melody:1.57.0"
}
// […]
Step 3. Refresh deps
grails refresh-dependencies
Step 4. Configure stuff in generated GrailsMelodyConfig.groovy
// if -DstorageDir is set and not empty, then use it, else try '/no-storage-dir-set' as fallback.
javamelody.'storage-directory' = "${System.properties['storageDir'] ?: '/no-storage-dir-set'}/javamelody"
Step 5. Build WAR
Step 6. Create setenv.sh in apache-tomcat 8.0.26
#! /bin/sh
export CATALINA_OPTS="$CATALINA_OPTS -DstorageDir=/media/tmpfs"
Step 7. Start Tomcat and deploy WAR created in Step 5 to ROOT context
Now open the monitoring page in browser.
http://www.localhost:8080/monitoring#systeminfo
shows that storageDir
-system-property was properly passed:
JVM arguments: -Djava.util.logging.config.file=/home/meyerfa/Tomcat/apache-tomcat-8.0.26/conf/logging.properties
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-DstorageDir=/media/tmpfs
-Djava.endorsed.dirs=/home/flxtr/Tomcat/apache-tomcat-8.0.26/endorsed
-Dcatalina.base=/home/flxtr/Tomcat/apache-tomcat-8.0.26
-Dcatalina.home=/home/flxtr/Tomcat/apache-tomcat-8.0.26
-Djava.io.tmpdir=/home/flxtr/Tomcat/apache-tomcat-8.0.26/temp
- But JavaMelody’s debugging logs show, that it obviously was not present during the GrailsMelodyConfig initialization, so the fallback were set:
JavaMelody 1.57.0 Debugging logs
Thu Dec 17 09:42:58 CET 2015 DEBUG JavaMelody listener init started
Thu Dec 17 09:42:58 CET 2015 DEBUG datasources found in JNDI: []
Thu Dec 17 09:42:58 CET 2015 DEBUG JavaMelody listener init done in 23 ms
Thu Dec 17 09:43:06 CET 2015 DEBUG JavaMelody filter init started
Thu Dec 17 09:43:06 CET 2015 DEBUG OS: Linux unknown, amd64/64
Thu Dec 17 09:43:06 CET 2015 DEBUG Java: Java(TM) SE Runtime Environment, 1.8.0_45-b14
Thu Dec 17 09:43:06 CET 2015 DEBUG Server: Apache Tomcat/8.0.26
Thu Dec 17 09:43:06 CET 2015 DEBUG Webapp context:
Thu Dec 17 09:43:06 CET 2015 DEBUG JavaMelody version: 1.57.0
Thu Dec 17 09:43:06 CET 2015 DEBUG JavaMelody classes loaded from: file:/home/flxtr/Tomcat/apache-tomcat-8.0.26/webapps/ROOT/WEB-INF/lib/javamelody-core-1.57.0.jar
Thu Dec 17 09:43:06 CET 2015 DEBUG Host: [email protected]
Thu Dec 17 09:43:06 CET 2015 DEBUG parameter defined: storage-directory=/no-storage-dir-set/javamelody
Thu Dec 17 09:43:06 CET 2015 DEBUG parameter defined: displayed-counters=http,sql,error,log,spring,jsp
Thu Dec 17 09:43:06 CET 2015 DEBUG log listeners initialized
Thu Dec 17 09:43:06 CET 2015 DEBUG datasources found in JNDI: []
Thu Dec 17 09:43:06 CET 2015 DEBUG counters initialized
Thu Dec 17 09:43:06 CET 2015 DEBUG counters data read from files in /no-storage-dir-set/javamelody/_falxDell
Thu Dec 17 09:43:06 CET 2015 DEBUG collect task scheduled every 60s
Thu Dec 17 09:43:06 CET 2015 WARN exception while collecting data: java.io.IOException: JavaMelody directory can't be created: /no-storage-dir-set/javamelody/_falxDell
Thu Dec 17 09:43:06 CET 2015 DEBUG first collect of data done
Thu Dec 17 09:43:06 CET 2015 DEBUG JavaMelody filter init done in 51 ms
Thu Dec 17 09:43:07 CET 2015 WARN exception while collecting data: java.io.IOException: JavaMelody directory can't be created: /no-storage-dir-set/javamelody/_falxDell
Also reproducible with Jetty. With grails run-app
in GGTS it works as expected.