Created
March 15, 2016 18:19
-
-
Save adam-hert/7a390a1746b71cc109d7 to your computer and use it in GitHub Desktop.
Tomcat6 + custom instrumentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//instructions for instrumenting a tomcat app and adding custom instrumentation | |
apt-get update | |
//Install the needfull java stuff | |
apt-get install -y tomcat6 ant openjdk-7-jdk | |
//install traceview base package | |
wget files.appneta.. yada yada yada | |
//install java instrumentation | |
sudo apt-get install tracelytics-java-agent tracelytics-java-agent-native | |
//Make Tomcat load our agent (tomcat's init script loads options from this file if it exists: setenv.sh ) | |
nano /usr/share/tomcat6/bin/setenv.sh | |
#!/bin/sh | |
JAVA_OPTS="$JAVA_OPTS -javaagent:/usr/local/tracelytics/tracelyticsagent.jar" | |
//make a Java app | |
cd /var/lib/tomcat6/webapps | |
mkdir sample | |
cd sample | |
mkdir WEB-INF | |
cd WEB-INF | |
mkdir {src,classes,lib} | |
//make the following files: | |
./web.xml | |
// | |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE web-app | |
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | |
"http://java.sun.com/dtd/web-app_2_3.dtd"> | |
<web-app> | |
<servlet> | |
<servlet-name>process</servlet-name> | |
<servlet-class>process</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>process</servlet-name> | |
<url-pattern>/process</url-pattern> | |
</servlet-mapping> | |
</web-app> | |
./src/process.java | |
// | |
import java.io.*; | |
import javax.servlet.*; | |
import javax.servlet.http.*; | |
import com.tracelytics.api.ext.*; | |
public class process extends HttpServlet { | |
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
try { | |
Thread.sleep(500); | |
} catch(InterruptedException ex){ | |
Thread.currentThread().interrupt(); | |
} | |
TraceEvent event = Trace.createEntryEvent("Custom_Middle_Layer"); | |
event.report(); | |
PrintWriter out = response.getWriter(); | |
out.println("Hello World"); | |
try { | |
Thread.sleep(200); | |
} catch(InterruptedException ex){ | |
Thread.currentThread().interrupt(); | |
} | |
TraceEvent new_event = Trace.createExitEvent("Custom_Middle_Layer"); | |
new_event.report(); | |
} | |
} | |
// | |
//cp some servlet class into this apps classes folder | |
cp /usr/share/tomcat6/lib/servlet-api.jar /var/lib/tomcat6/webapps/sample/WEB-INF/lib/ | |
//cp our API jar to the same spot | |
cp /usr/local/tracelytics/tracelytics-api.jar /var/lib/tomcat6/webapps/sample/WEB-INF/lib/ | |
//move to src | |
cd /var/lib/tomcat6/webapps/sample/WEB-INF/src | |
//compile the process.java with the proper classpaths | |
javac -cp ../lib/tracelytics-api.jar:../lib/servlet-api.jar process.java | |
//move the newly created class to ../classes | |
cp process.class ../classes | |
service tomcat6 restart | |
curl localhost:8080/sample/process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment