mod_stopwatch

acme on 2004-04-05T08:05:50

All I seem to do these days is to write monitoring tools. sky prodded me to investigate getting Apache to give decent information on how long requests take to process. It has a T option which can report in seconds, but that's way too low resolution. May I present mod_stopwatch, which gives microsecond resolution:

192.168.5.254 - - [02/Apr/2004:17:22:48 +0100] "GET / HTTP/1.1" 200 1456 (1525 usecs)
192.168.5.254 - - [02/Apr/2004:17:22:48 +0100] "GET /apache_pb.gif HTTP/1.1" 200 2326 (89 usecs)
Note that the index page takes longer than the GIF as it must go through mod_dir etc. Now if only there was an CAAN to upload this to...


I like to watch...

merlyn on 2004-04-05T11:04:12

Here's how I get CPU times:
package Stonehenge::Timeit;
use strict;

## usage: PerlInitHandler Stonehenge::Timeit;

use vars qw($VERSION);
$VERSION = (qw$Revision: 1.1.1.1 $ )[-1];

use Apache::Constants qw(OK DECLINED);
use Apache::File;
use Apache::Log;

sub handler {
  ## use Stonehenge::Reload; goto &handler if Stonehenge::Reload->reload_me;

  my $r = shift;
  return DECLINED unless $r->is_initial_req;
  my $log = $r->log;        # closure
  my $uri = $r->uri;        # closure

  my @times = (time, times);    # closure

  $r->register_cleanup
    (sub {
       $log->notice(sprintf "%s times: real %d user %.2f sys %.2f",
            $uri, (map { $_ - shift @times } time, times)[0,1,2]);
       return OK;
     });

  return DECLINED;
}
1;

CAAN

echo on 2004-04-05T13:58:29

Now if only there was an CAAN to upload this to...

Check out http://modules.apache.org/

Re:CAAN

acme on 2004-04-05T15:28:16

Wow, that's really hard to find from http://httpd.apache.org/. I completely missed it looking at http://httpd.apache.org/modules/. Also, 316 modules and no index is a bit annoying. But yes, all this ranting is because I had been able to find it then I would have used mod_chronometer...