Return-Path: Delivered-To: apmail-httpd-modules-dev-archive@locus.apache.org Received: (qmail 49971 invoked from network); 9 Oct 2008 13:26:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Oct 2008 13:26:37 -0000 Received: (qmail 95402 invoked by uid 500); 9 Oct 2008 13:26:35 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 95373 invoked by uid 500); 9 Oct 2008 13:26:35 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 95362 invoked by uid 99); 9 Oct 2008 13:26:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Oct 2008 06:26:35 -0700 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=DNS_FROM_SECURITYSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sorinm@gmail.com designates 64.233.184.229 as permitted sender) Received: from [64.233.184.229] (HELO wr-out-0506.google.com) (64.233.184.229) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Oct 2008 13:25:32 +0000 Received: by wr-out-0506.google.com with SMTP id c57so5632wra.4 for ; Thu, 09 Oct 2008 06:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=ct6IAfhkzAcnEBFrdRngnVfJwBPgAFCvkXWllVWh1Ao=; b=gdDUbwylbBKqxoi0q5pUQXFQHtGXMobcttJqFD5UaOimNCvngGyC+2tOafbPX+JW6P EDlm3xx4h5r4fhTLy5HF8v7SyX597iGfJwfnh6Jo3rmpw7nEZPVjdotJgjcIUZj70BmS K2EIgNfhnaKtb3/HxVCUSts5JksoV1T3CfRPA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=GK60sjfEuGXfXkhQe00d46HrBDYQfuoJuLSTkmUbAGo/pl4kYNx+SCzplEvnwdH+NR xNVdzeCj/fmCP8mmIef2iL8P/pdvZz+hqRWV7Qzu1GBtbMRv+BzTMW8tzcH+5G5BW3Ha DFsd+YxKry1P0E4Jnd2DtMbZTHJ8+2NC5w4PE= Received: by 10.142.141.21 with SMTP id o21mr37939wfd.213.1223558750476; Thu, 09 Oct 2008 06:25:50 -0700 (PDT) Received: by 10.143.3.19 with HTTP; Thu, 9 Oct 2008 06:25:50 -0700 (PDT) Message-ID: <20170a030810090625t44209259v26b4d78be5f94ac0@mail.gmail.com> Date: Thu, 9 Oct 2008 15:25:50 +0200 From: "Sorin Manolache" To: modules-dev@httpd.apache.org Subject: Re: number of bytes/packets sent/received In-Reply-To: <20170a030810090611s240ec6f3w7fd5eaf41fb1de7e@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6456355d0810090540s30edaabfx9491ba47f2c6b9bf@mail.gmail.com> <20170a030810090611s240ec6f3w7fd5eaf41fb1de7e@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org 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. Sorin