----- Original Message ----- From: "Steven J. Owens" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Tuesday, November 09, 2004 9:40 PM
Subject: Re: Counting Page Hits
On Tue, Nov 09, 2004 at 05:55:07PM -0800, Justin Jaynes wrote:What is the easiest way to monitor hits to resources (files or pages) on my tomcat 5 server?
Do I write my own ticker into each page I want to monitor and store the incremented value to a database?
Or is there a much simpler solution already implimented in some tomcat management software
AFAIK there isn't any sort of built-in monitoring. The general answer I've seen in the past is that you should use log analysis tools on the logs, which are in a fairly standard format. This probably makes a ton of sense, considering that adding special monitoring would involve adding overhead to every page request, while log analysis could be done to the logs on a separate machine.
An alternative would be to code a servlet filter to log the requested URLs. In some ways a servlet filter is much like a servlet; you request a URL, based on an entry in web.xml the servlet engine hands the request to the appropriate servlet filter instance (or if the servlet filter hasn't be instantiated yet, instantiates it and then hands the request to the instance).
The way it's *not* like a servlet is that the servlet filter's doFilter() method gets request, response AND chain. Besides messing with the request and response object all it likes (subject to the standard limitations, like you can't write headers once you've started flushing body content back to the client), the filter can call chain.doFilter(request, response), which forwards the request to the original servlet it was intended for.
So in this case, you'd set up a servlet filter, define the URL mappings to filter all the servlets and JSPs you care about monitoring, and have it print a log message to a special log file (or to a special logging channel).
http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters.html http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html http://www.onjava.com/pub/a/onjava/2004/03/03/filters.html
-- Steven J. Owens [EMAIL PROTECTED]
"I'm going to make broad, sweeping generalizations and strong, declarative statements, because otherwise I'll be here all night and this document will be four times longer and much less fun to read. Take it all with a grain of salt." - http://darksleep.com/notablog
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]