Hi, My requirement is to measure the request and response bandwidth of a webapp that's deployed in Tomcat. Basically capture each request and response bandwidth and store the statistics and do analytics on that data overtime.
We've already written a custom Tomcat Valve to capture plenty of information regarding requests coming to a webapp. Since both request and response go through the Valve, I think there should be a way to capture bandwidth stats in the Valve, but haven't found out how to do it. One thing we've done previously is to get this information using the Tomcat RequestInfo.java class. This however doesn't seem like a clean solution. While digging into the tomcat code, I noticed that we can get the org.apache.coyote.Request object (that's used in RequestInfo class) in the Valve as follows; *org.apache.catalina.connector.request.getCoyoteRequest().getBytesRead(); // 0org.apache.catalina.connector.request.getCoyoteRequest().getResponse().getContentWritten(); // 0* But both the above statement always returns 0, which is wrong compared to the output in RequestInfo class. Another thing I noticed is that we can get a RequestInfo object within the valve as follows; *reqProcessorMX = request.getCoyoteRequest().getRequestProcessor();* Now if I try to use the *reqProcessorMX* object and call *getBytesSent()*method it returns the accumulated bytes count and not the per request bandwidth. This is what I've managed to gather so far. Any idea on what could be the issue? Why the coyote.Request is not returning the correct bandwidth in the Valve? Is there a better way to capture request/response bandwidth, within a Valve ?! Many thanks in advance. Thanks & Regards, Shariq.