On Wed, Jul 17, 2013 at 9:49 PM, Christopher Schultz < ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > Shariq, > > On 7/17/13 12:12 PM, Shariq wrote: > > Hi Christopher, > > > > > > On Wed, Jul 17, 2013 at 9:32 PM, Christopher Schultz < > > ch...@christopherschultz.net> wrote: > > > > Shariq, > > > > On 7/17/13 8:47 AM, Shariq wrote: > >>>> On Wed, Jul 17, 2013 at 5:49 PM, André Warnier > >>>> <a...@ice-sa.com> wrote: > >>>> > >>>>> Shariq wrote: > >>>>> > >>>>>> 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. > >>>>>> > >>>>> > >>>>> Bandwith > >>>>> (http://en.wikipedia.org/wiki/**Bandwidth_%28computing%29< > > http://en.wikipedia.org/wiki/Bandwidth_%28computing%29> > >>>>> > >>>>> > > ) > >>>>> refers to a number of bits/second transmitted over a > >>>>> communications channel. > >>>>> > >>>>> This is typically something better captured by network > >>>>> equipment (analysers, routers, switches), and it doesn't > >>>>> really make much sense on an application base. > >>>>> > >>>>> Apart from that, the AccesLogValve can already tell you, on > >>>>> a URL base, how much total time was needed to fulfill the > >>>>> request, and how many bytes (x 8 bits) were sent as a > >>>>> response. (You can probably also get the number of bytes of > >>>>> the request). > >>>>> > >>>>> But Tomcat is not the only element which intervenes here, > >>>>> and the real bandwidth can also be limited by what the > >>>>> client (and everything in-between) can absorb. > >>>>> > >>>>> Maybe before we go any further into this, you would like to > >>>>> make more clear what exactly you are trying to measure, and > >>>>> for which purpose ? > >>>>> > >>>> > >>>> What I am trying to measure is the size (number of bytes) of > >>>> the request / response for a webapp. So overtime we can > >>>> produce statistics such as, for a given time interval how > >>>> much bytes was served by server / tomcat for a particular > >>>> webapp. Also we are looking to throttle webapps consuming a > >>>> high bandwidth etc. > >>>> > >>>> The idea is gather raw statistics and process / aggregate > >>>> them overtime ... > > > > I think what you are looking for is a typical web server access > > log. Just log the bytes read/written for each request, and use one > > of the many fine (and freely-available) tools out on the Internet > > to run statistics on your web server logs. > > > > > >> Yes this is pretty much what I want to do, but I am still not > >> able to find out how to get the bytes read/written in the valve. > >> Any pointers on how I could find the bytes read/written for each > >> request with a tomcat valve ?! > > http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Log_Valve > > Look at the "pattern" attribute details. I think you are looking for > "%b". Note that %b excludes headers. If you want "bytes read", you can > use %{Content-Length}i -- again, that will be side excluding headers. > > I don't believe Tomcat supports httpd-style %I and %O (which require a > separate module to be enabled on the Tomcat side). I'm not sure how > much work that would be to enable. > I am still having some issue. Llooking at the AccessLog valve code, it seems we can get the response size as follows; response.getBytesWritten(false); above returns the correct message size, how ever when I try it in my custom valve it always returns zero '0'. However if I pass "*true*" as the argument to "*getBytesWritten*" method I get the correct message size, any idea why that happens? Also is it correct to pass "true"? What are the implications, issue that could arise? Passing true tries to *commit* the request right, (from what I gather from the code), so wonder if this could cause issues ?! Also with regards to getting the request size, only thing that worked for me so far is; request.getCoyoteRequest().getContentLengthLong(); Is this the most reliable and correct way to do this ?! Please advice. > - -chris > -----BEGIN PGP SIGNATURE----- > Version: GnuPG/MacGPG2 v2.0.17 (Darwin) > Comment: GPGTools - http://gpgtools.org > Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ > > iQIcBAEBCAAGBQJR5sP6AAoJEBzwKT+lPKRYv4EP/3+wAOMcMrS8CrgC4DjOmcU1 > 0WVu1qayJYVqyyTeG8V5sbfBvzOeoJOWL3VAxBBhHdGB5T/VlOO+WYno/6Lwy1JD > vnY0PAhUVZ4O7ROgtbJPa6ft4e/mZnCnQkfESJw+i1hBq30iSgt3GkdQ59mD8K3i > ygTmUujm7ObJsdO3Zdq81aqfZmWG0EfolChgDNBA12JkLqVjObBvUj9GtGGW3UVb > V5cbHgeggkiGMEzY6WwwURo8HjuD0iJ8YJM/CBfZDwkCkgk6PFCtltuZfEnmIijy > 5gbh9dBLoEJWFQUQ6bB80lF+qihljstu6vuNq5wtvTrqwKBVQS4Xw5rbaC9LoT29 > YWHs69Y/rS8dy/aqVCpcKzZNApFmXNUmMnOAvuNt2ABf9CGPVi05NjnclxyuFjUR > N+EHfSCigza2dFsr80cSi+H8AfB1tqtZueGBjLqXlVEG3HLS+zNNm8t0F8O1USA/ > N79jSQRz5rs7DdkkNYvsgk/ltXcamhN3RplShXdlWqJrM571hZPPJ82vp/KFWsVV > p4AAwWrCGyg6mzLlYY9tLFpzxuQ4QV+bAsHsIzd403lklp0KiqMzaK7/+oc3sry/ > AwRCMiid5wifarXyj9LHV0oV2HJU7yiA4QA1UEqHL2AnD9BNzf5hDQyJHjFHrFak > K/to3t+D5nyFVb9LWCa0 > =PS2C > -----END PGP SIGNATURE----- > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >