Monday, 10 June 2013

logging HTTP Requests in Tomcat


[STEP 1] Add/Uncomment following Valve Component to conf/server.xml

<!-- Access log processes all example.
     Documentation at: /docs/config/valve.html
     Note: The pattern used is equivalent to using pattern="common" -->

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t %I &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>

where, %I = thread name
[STEP 2] cat GET requests
Only to count number of GET requests
$ cat apache-tomcat-6.0.26/logs/* | grep GET | wc -l
2238

To view all GET requests asynchronously (in production)
$ tail -f apache-tomcat-6.0.26/logs/* | grep GET --ignore-case
Mapped "{[/sessionexpired],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.zazzercode.eccount.server.controller.PaymentController.sessionExpired(org.springframework.ui.ModelMap)

In dev mode, using eclipse
$ tail -f eclipse_workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/logs/* | grep GET


There also exists an Open source tool Java Melody for Tomcat Requests Monitoring.


                                                       Fig. Request Statistics


References
Best tools to monitor Tomcat, http://stackoverflow.com/a/1533254/432903

No comments:

Post a Comment