Re: Apache bandwidth calculating
Thank you all. OK Let me ask again, are there any way to store a web site bandwidth statistics in a file or a database - Original Message - From: "Ged Haywood" <[EMAIL PROTECTED]> To: "Abd El-Hameed Mohammed" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Sunday, October 05, 2003 12:45 PM Subject: Re: Apache bandwidth calculating > Hi there, > > On Fri, 3 Oct 2003, Abd El-Hameed Mohammed wrote: > > > Do any one know where i can find the source of mod_bwlimited > > or any recources for modules like it. > > http://modules.apache.org/search > > Type the word "bandwidth" into the box. > > Try CPAN too, and you might want to look at > > http://www.modperlcookbook.org/chapters/ch13.pdf > > in which Geoff which mentions mod_throttle_access > (and brings us more-or-less back on-topic:). > > 73, > Ged. > > [This E-mail scanned for viruses using McAfee.] > > >
Re: Apache bandwidth calculating
Hi there, On Tue, 7 Oct 2003, Abd El-Hameed Mohammed wrote: > Let me ask again, are there any way to store a web site bandwidth statistics > in a file or a database Well a gentle reminder didn't work. This is the mod_perl Mailing List, and your question is not appropriate here. 73, Ged.
RE: [QUESTION] Relating a request to a response
Thanks for your help on this issue. I have modified my code so that it uses the same technique as the one you wrote, and it's now working quite well :) I'm quite interested in the idea of having a generalized bit of code to modify HTTP headers. However, I'm not a particularly experienced Perl programmer, and have little knowledge of Mod_Perl's interaction with Apache. Thanks once again for your help. It would have taken me a very long time to overcome this problem without it. --- Regards, Chris Pringle UK PSG Hewlett-Packard, Bristol Tel: +44 117 31 29664 > -Original Message- > From: Stas Bekman [mailto:[EMAIL PROTECTED] > Sent: 07 October 2003 02:12 > Cc: Pringle, Chris (HP-PSG); [EMAIL PROTECTED] > Subject: Re: [QUESTION] Relating a request to a response > > > Stas Bekman wrote: > [...] > > The following is a much more generic example than you need, so you > > will > > be able to simplify it a great deal. I'll commit that soon as a new > > test. I see some problem which I need to debug more, but it > won't affect > > your task. > > I've committed a fix to this problem. the test that I > committed earlier > demonstrates how to write filters that manipulate only HTTP > headers, without > ever touching or even seeing the request/response body. > > I thought a bit more about your request and came to > conclusion that it should > be trivial to generalize this code and put it on CPAN as > Apache::FilterHeadersManip, which will be very simple to use > for end users. > You will need to provide a callback function, which will > receive a ref to an > array of headers (input or output), which that callback will > manipulate, by > changing and/or removing the existing headers and/or adding > new ones. Once > this callback returns Apache::FilterHeadersManip will use the > correct way to > flush the headers in that array. > > __ > Stas BekmanJAm_pH --> Just Another mod_perl Hacker > http://stason.org/ mod_perl Guide ---> http://perl.apache.org > mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com > http://modperlbook.org http://apache.org http://ticketmaster.com > >
Re: Apache bandwidth calculating
In Tue, 7 Oct 2003, Abd El-Hameed Mohammed wrote: > Thank you all. > OK > Let me ask again, are there any way to store a web site bandwidth statistics > in a file or a database Yes. I adapted some of the Apache::AuthDBI module into a logging hook that interfaces to a database via dbi via custom query(ies). You can use tokens I've defined to insert just about any of the available retrievable information from the objects available to a module into the custom queries. You can use this to execute any custom query on a database with time and bandwidth used, for instance thus allowing you to generate the most detailed bandwidth statistics you could ever want, or as general as you like. Group it how you please. This is not a fully tested module. Use at your own risk. Help me make it better. Perldoc should work on it to help you figure out how to use the tokens. Ask if you hvae any questions, and please let me know of any suggestions for improvements! With intrepidation, here is the code. Skylos --- package Apache::ActivityLogDBI; use Apache (); use Apache::Constants qw( OK SERVER_ERROR ); use DBI (); use strict; # $Id: ActivityLogDBI.pm,v 0.01 2003/10/07 08:36:38 ask Exp $ require_version DBI 1.00; $ActivityLogDBI::VERSION = '0.01'; # 1: report about cache miss # 2: full debug output $ActivityLogDBI::DEBUG = 0; # configuration attributes, defaults will be overwritten with values from .htaccess. my %Config = ( 'Activity_Log_DBI_data_source' => '', 'Activity_Log_DBI_username' => '', 'Activity_Log_DBI_password' => '', ); # stores the configuration of current URL. # initialized during authentication, eventually re-used for authorization. my $Attr = { }; # rectify queries with the appropriate information sub subvars { my $r = shift; my $query = shift; my $dbh = shift; my $s = $r->server; my $c = $r->connection; my $vals = { CONNECTION_REMOTEHOST => sub { $c->remote_host(); }, CONNECTION_REMOTEIP => sub { $c->remote_ip(); }, CONNECTION_REMOTELOGNAME => sub { $c->remote_logname(); }, CONNECTION_USER => sub { $c->user(); }, CONNECTION_AUTHTYPE => sub { $c->auth_type(); }, CONNECTION_ABORTED => sub { $c->aborted(); }, REQUEST_METHOD => sub { $r->method(); }, REQUEST_BYTES => sub { $r->bytes_sent(); }, REQUEST_HEADER => sub { $r->header_only(); }, REQUEST_PROTOCOL => sub { $r->protocol(); }, REQUEST_HOSTNAME => sub { $r->hostname(); }, REQUEST_TIME => sub { my @d = localtime($r->time()); sprintf '%04d-%02d-%02d %02d:%02d:%02d', 1900+$d[5], 1+$d[4], $d[3], $d[2], $d[1], $d[0]; }, REQUEST_URI => sub { $r->uri(); }, REQUEST_FILENAME => sub { $r->filename(); }, REQUEST_LOCATION => sub { $r->location(); }, REQUEST_PATH_INFO => sub { $r->path_info(); }, REQUEST_ARGS => sub { $r->args(); }, SERVER_DOCUMENTROOT => sub { $s->document_root(); }, SERVER_SERVERROOT => sub { $s->server_root_relative(); }, SERVER_SERVERPORT => sub { $s->get_server_port(); }, SERVER_ADMIN => sub { $s->server_admin(); }, SERVER_HOSTNAME => sub { $s->server_hostname(); }, SERVER_ISVIRTUAL => sub { $s->server_is_virtual(); }, SERVER_UID => sub { $s->uid(); }, SERVER_GID => sub { $s->gid(); }, SERVER_LOGLEVEL => sub { $s->loglevel(); }, }; foreach (keys %{$vals}) { if ($query =~ /$_/) { my $value = $dbh->quote($vals->{$_}->()); $query =~ s/$_/$value/g; } } return $query; } # log handler sub log { my ($r) = @_; my ($key, $val, $dbh); my $prefix = "$$ ActivityLogDBI::log"; if ($ActivityLogDBI::DEBUG > 1) { my ($type) = ''; $type .= 'initial ' if $r->is_initial_req; $type .= 'main' if $r->is_main; print STDERR "==\n$prefix request type = >$type< \n"; } return OK unless $r->is_initial_req; # only the first internal request print STDERR "REQUEST:\n", $r->as_string if $ActivityLogDBI::DEBUG > 2; # get username my ($user_sent) = $r->connection->user; print STDERR "$prefix user sent = >$user_sent<\n" if $ActivityLogDBI::DEBUG > 1; # get configuration while(($key, $val) = each %Config) { $val = $r->dir_config($key) || $val; $key =~ s/^Activity_Log_DBI_//; $Attr->{$key} = $val; printf STDERR "$prefix Config{ %-16s } = %s\n", $key, $val if $ActivityLogDBI::DEBUG > 1; } my @queries; my $temp = $r->dir_config(); while(($key, $val) = each %{$temp}) { next unless ($key =~ /^Activity_Log_DBI_Query/); push @queries, $val; printf STDERR "$prefix Config{ %-16s } = %s\n", $key, $val if $ActivityLogDBI::DEBUG > 1; } undef $temp; unless (scalar @queries) { printf STDERR "$prefix No queries - return OK\n" if $ActivityLogDBI::DEBUG > 1; return OK; } # parse connect attributes, which may be tilde separated lists my @data_sources = split(/~/, $Attr->{data_source});
Re: [QUESTION] Relating a request to a response
Pringle, Chris (HP-PSG) wrote: Thanks for your help on this issue. I have modified my code so that it uses the same technique as the one you wrote, and it's now working quite well :) I'm quite interested in the idea of having a generalized bit of code to modify HTTP headers. However, I'm not a particularly experienced Perl programmer, and have little knowledge of Mod_Perl's interaction with Apache. Thanks once again for your help. It would have taken me a very long time to overcome this problem without it. Good to hear that. I might do that somewhere next week and post an announcement here. __ Stas BekmanJAm_pH --> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
register_cleanup() in PerlInitHandler harmful?
I have a dumb question about register_cleanup() in Apache 1.x and mod_perl 1.27. yesterday I released Apache::Profiler to dump slow URI to log file, which seems to be useful. However it uses register_cleanup() in PerlInitHandler and it seems to break whole things because of, I guess, register_cleanup breakage. (e.g. Apache::Request's param() method returns same value ignoring QUERY_STRING, once compiled.) Apache::Profiler is here: http://search.cpan.org/~miyagawa/Apache-Profiler-0.01/ (Don't try this on production environment, it's broken) Any helps appreciated. Thanks, -- Tatsuhiko Miyagawa <[EMAIL PROTECTED]>
[mp2 module rfc] Apache::Filter::HTTPHeadersManip
As I was writing for Chris the test that manipulates HTTP headers and seeing that it's not trivial for the end users (due to the http_in core httpd filter's implementation), I've realized that the functionality of manipulating HTTP headers can be abstracted, letting the end user do very little work. So I came up with Apache::Filter::HTTPHeadersManip which you can try http://apache.org/~stas/Apache-Filter-HTTPHeadersManip-0.01.tar.gz While working on this code I have discovered a bug in modperl-1.99_10, which is now fixed in cvs. Therefore to try this module you need the cvs version or 1.99_11 (which is not released at the moment). The module comes with a full test suite, so you can see it in action. To write a new header manipulator all you need to do is to subclass this package and provide a simple function that manipulates the headers, e.g.: # MyApache/FixupInputHTTPHeaders.pm package MyApache::FixupInputHTTPHeaders; use base qw(Apache::Filter::HTTPHeadersManip); sub manip { my ($class, $ra_headers) = @_; # modify a header for (@$ra_headers) { s/^(Foo).*/$1: Moahaha/; } # push header (don't forget "\n"!) push @$ra_headers, "Bar: MidBar\n"; } 1; and then add to httpd.conf PerlInputFilterHandler +MyApache::FixupInputHTTPHeaders and voila, without using mod_perl HTTP callbacks you get to manipulate HTTP (input and output) headers for any other Apache module. Chris wanted this for his proxy module, which should work as well. If you have comments regarding the naming or implementation/interface of this module please let me know before I release the first version on CPAN. BTW, this module is smart enough not to filter request/response bodies. Though due to a bug in httpd, it can't be removed from the filters chain when its work is done, so it passively passes the data though itself. Hopefully one day that httpd bug will be fixed. __ Stas BekmanJAm_pH --> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com