httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sorin Manolache" <>
Subject Re: number of bytes/packets sent/received
Date Thu, 09 Oct 2008 13:25:50 GMT
On Thu, Oct 9, 2008 at 15:11, Sorin Manolache <> wrote:
> On Thu, Oct 9, 2008 at 14:40, Andrej van der Zee
> <> wrote:
>> Hi,
>> I was wondering what would be the right way to get the number of bytes
>> / packets that are sent / received in an Apache module for httpd-2.1
>> and higher (including the HTTP headers).
> Check server/core.c and server/core_filters.c in the apache sources.
> There are two filters there, ap_core_input_filter and
> ap_core_output_filter. They are the first input/last output filters.
> They are responsible of packaging the byte stream from the socket into
> bucket brigades and of writing the contents of bucket brigades to the
> socket. So, the output of ap_core_input_filter is really was comes
> from the socket, and the input of ap_core_output_filter is really was
> goes to the socket.
> So you'll need to write your own filters that count the bytes and
> insert them immediately after/before ap_core_input/output_filter.
> This, if you want to count the headers. If not, for output it would be
> easier to parse the access logs. For input, I don't know.
> Wouldn't it be easier if you don't do this in apache but with some
> sort of network monitoring tools? iptables, snmp, or something like
> that? I'm not an expert, but I suppose some smart tools must be out
> there, allowing you to filter by source IP, port, etc.
> Sorin

Giving it a second thought, the problem looks complicated. Such
filter-based counters would count the traffic of _one_ apache process.
When you increment the counter, you have to protect it from concurrent
access by other threads running in the same apache child process.
Then, before the apache child process exits, you need to add the
counter to a global counter shared among apache child processes (which
has to be protected against race conditions as well). It's really
hairy. Don't do it in apache.


View raw message