Search code examples
javatomcatdockernewrelicsupervisord

Docker container with newrelic java agent and supervisord not sending data on first launch


We have a docker container that runs a java7 application in tomcat7 via supervisord. We want to monitor the APM via newrelic.

Here is the supervisord config file

[program:tomcat]
command=/home/ec2-user/tomcat7/bin/catalina.sh run
environment=CATALINA_OPTS=" -javaagent:/home/ec2-user/tomcat7/newrelic/newrelic.jar"

Here is where we add our newrelic.yml config file in the Dockerfile

COPY newrelic.yml /home/ec2-user/tomcat7/newrelic/newrelic.yml

When the docker container starts, it runs supervisord, which starts the java application correctly. Although, if we connect to the container and go to the tomcat7/newrelic folder, we see no logs folder created. No data is sent to newrelic, even if ps aux | grep tomcat shows us that the
-javaagent option is correctly passed:

/usr/bin/java -Djava.util.logging.config.file=/home/ec2-user/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -javaagent:/home/ec2-user/tomcat7/newrelic/newrelic.jar -Djava.endorsed.dirs=/home/ec2-user/tomcat7/endorsed -classpath /home/ec2-user/conf:/home/ec2-user/tomcat7/bin/bootstrap.jar:/home/ec2-user/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/home/ec2-user/tomcat7 -Dcatalina.home=/home/ec2-user/tomcat7 -Djava.io.tmpdir=/home/ec2-user/tomcat7/temp org.apache.catalina.startup.Bootstrap start

If we kill the tomcat7 process in the container, supervisord restarts the process, and then we see the "logs" folder appear and data is being correctly sent to newrelic.

Is there any reason why the first time supervisord starts the process the newrelic agent does not attach, but does on the second start?

  • supervisord version: 3.1.3
  • newrelic agent version : 3.21.0
  • tomcat version: 7
  • java version: 7
  • docker version: 1.7.1

Solution

  • We found the problem: the temp folder was missing from our tomcat. The newrelic agent will not start if the folder does not exist, but it creates it. This explains why the 2nd time we started the process, the agent hooked correctly.