Skip to content

Instantly share code, notes, and snippets.

@adam-hert
Last active December 8, 2016 02:51
Show Gist options
  • Save adam-hert/009ee956e05515b95a891a76963c928b to your computer and use it in GitHub Desktop.
Save adam-hert/009ee956e05515b95a891a76963c928b to your computer and use it in GitHub Desktop.

This is an example gist showing how to instrument a tomcat server with Traceview inside an apline linux docker container.

####Running the tracelyzer outside the container When you run the tracelyzer on the host instead of the container you need to do two things

  1. Set the address to report to via the environment variable TRACEVIEW_UDPADDR this can be done in the Dockerfile or set at runtime.
  2. You need to share the following volume between the host where the tracelyzer is running and the container /var/lib/tracelyzer Example: docker run -e "TRACEVIEW_UDPADDR=127.0.0.1" -v /var/lib/tracelyzer:/var/lib/tracelyzer dockerimage

Lastly you need to make the tracelyzer on the host listen on all interfaces: Debian-based: edit /etc/default/tracelyzer and update/add LISTEN_HOST=0.0.0.0 Redhat-based: edit /etc/sysconfig/tracelyzer and update/add LISTEN_HOST=0.0.0.0 (restart tracelyzer after changing)

####App Config App config is handled automatically via an API call inside setenv.sh, the site key needs to be added (without <>) and the other parameters can be alterred. Tomcat automatically runs setenv.sh from within catalina.sh, this may need to be alterred depending on your environment.

FROM jeanblanchard/java:8
MAINTAINER Jean Blanchard <[email protected]>
# Expose web port
EXPOSE 8080
# Tomcat Version
ENV TOMCAT_VERSION_MAJOR 8
ENV TOMCAT_VERSION_FULL 8.5.8
# Download and install
RUN apk add --update curl &&\
curl -LO https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_VERSION_MAJOR}/v${TOMCAT_VERSION_FULL}/bin/apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz &&\
curl -LO https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_VERSION_MAJOR}/v${TOMCAT_VERSION_FULL}/bin/apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 &&\
md5sum -c apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 &&\
gunzip -c apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz | tar -xf - -C /opt &&\
rm -f apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 &&\
ln -s /opt/apache-tomcat-${TOMCAT_VERSION_FULL} /opt/tomcat &&\
rm -rf /opt/tomcat/webapps/examples /opt/tomcat/webapps/docs &&\
rm -rf /var/cache/apk/*
# Set environment
ENV CATALINA_HOME /opt/tomcat
#Install Traceview
RUN mkdir /usr/local/tracelytics && \
wget -P /usr/local/tracelytics/ http://files.appneta.com/java/tracelyticsagent.jar && \
wget -P /usr/local/tracelytics/ http://files.appneta.com/java/javaagent.json
#Set reporting address for traceview (applies when the tracelyzer is not in the container)
ENV TRACEVIEW_UDPADDR="127.0.0.1"
#Add traceview jar to tomcat
COPY setenv.sh ${CATALINA_HOME}/bin/setenv.sh
# Launch Tomcat on startup
CMD ${CATALINA_HOME}/bin/catalina.sh run
#!/bin/sh
JAVA_OPTS="$JAVA_OPTS -javaagent:/usr/local/tracelytics/tracelyticsagent.jar"
curl https://api.tv.solarwinds.com/api-v2/assign_app \
-d key=<site key> \
-d hostname=$(hostname) \
-d appname=java_test \
-d layer=tomcat \
-d create=True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment