From: Stefan Fritsch Date: Thu, 8 Oct 2009 21:42:13 +0000 (+0000) Subject: mod_logio: introduce new optional function ap_logio_get_last_bytes to get X-Git-Tag: 2.3.3~184 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92023763f1e20e3e36151dafd4d81014e230907e;p=apache mod_logio: introduce new optional function ap_logio_get_last_bytes to get total byte count of last request. core: Use ap_logio_get_last_bytes to report more accurate byte counts in mod_status if mod_logio is loaded. Without mod_logio, don't increment counts for HEAD requests. PR: 25656 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@823337 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index ef5c5c8916..7abfc2b949 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ Changes with Apache 2.3.3 mod_proxy_ftp: NULL pointer dereference on error paths. [Stefan Fritsch , Joe Orton] + *) mod_logio/core: Report more accurate byte counts in mod_status if + mod_logio is loaded. PR 25656. [Stefan Fritsch] + *) mod_ldap: If LDAPSharedCacheSize is too small, try harder to purge some cache entries and log a warning. Also increase the default LDAPSharedCacheSize to 500000. This is a more realistic size suitable diff --git a/include/ap_mmn.h b/include/ap_mmn.h index d505475dfa..4641f348af 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -198,15 +198,17 @@ * 20090401.3 (2.3.3-dev) Added DAV options provider to mod_dav.h * 20090925.0 (2.3.3-dev) Added server_rec::context and added *server_rec * param to ap_wait_or_timeout() + * 20090925.1 (2.3.3-dev) Add optional function ap_logio_get_last_bytes() to + * mod_logio * */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ #ifndef MODULE_MAGIC_NUMBER_MAJOR -#define MODULE_MAGIC_NUMBER_MAJOR 20090401 +#define MODULE_MAGIC_NUMBER_MAJOR 20090925 #endif -#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/http_core.h b/include/http_core.h index da4b8e6c80..2583493609 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -646,6 +646,8 @@ APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_out, APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_in, (conn_rec *c, apr_off_t bytes)); +APR_DECLARE_OPTIONAL_FN(apr_off_t, ap_logio_get_last_bytes, (conn_rec *c)); + /* ---------------------------------------------------------------------- * * ident lookups with mod_ident diff --git a/modules/loggers/mod_logio.c b/modules/loggers/mod_logio.c index fa8dc2178f..6de18a20b4 100644 --- a/modules/loggers/mod_logio.c +++ b/modules/loggers/mod_logio.c @@ -53,6 +53,7 @@ static const char logio_filter_name[] = "LOG_INPUT_OUTPUT"; typedef struct logio_config_t { apr_off_t bytes_in; apr_off_t bytes_out; + apr_off_t bytes_last_request; } logio_config_t; /* @@ -75,6 +76,18 @@ static void ap_logio_add_bytes_in(conn_rec *c, apr_off_t bytes){ cf->bytes_in += bytes; } +/* + * Optional function to get total byte count of last request for + * ap_increment_counts. + */ + +static apr_off_t ap_logio_get_last_bytes(conn_rec *c) +{ + logio_config_t *cf = ap_get_module_config(c->conn_config, &logio_module); + + return cf->bytes_last_request; +} + /* * Format items... */ @@ -104,6 +117,8 @@ static int logio_transaction(request_rec *r) logio_config_t *cf = ap_get_module_config(r->connection->conn_config, &logio_module); + /* need to save byte count of last request for ap_increment_counts */ + cf->bytes_last_request = cf->bytes_in + cf->bytes_out; cf->bytes_in = cf->bytes_out = 0; return OK; @@ -173,6 +188,7 @@ static void register_hooks(apr_pool_t *p) APR_REGISTER_OPTIONAL_FN(ap_logio_add_bytes_out); APR_REGISTER_OPTIONAL_FN(ap_logio_add_bytes_in); + APR_REGISTER_OPTIONAL_FN(ap_logio_get_last_bytes); } module AP_MODULE_DECLARE_DATA logio_module = diff --git a/server/scoreboard.c b/server/scoreboard.c index a1a3dbb7db..0831b6351c 100644 --- a/server/scoreboard.c +++ b/server/scoreboard.c @@ -64,6 +64,8 @@ static APR_OPTIONAL_FN_TYPE(ap_proxy_lb_workers) *pfn_proxy_lb_workers; static APR_OPTIONAL_FN_TYPE(ap_proxy_lb_worker_size) *pfn_proxy_lb_worker_size; +static APR_OPTIONAL_FN_TYPE(ap_logio_get_last_bytes) + *pfn_ap_logio_get_last_bytes; struct ap_sb_handle_t { int child_num; @@ -116,6 +118,8 @@ AP_DECLARE(int) ap_calc_scoreboard_size(void) if (lb_limit && lb_size) scoreboard_size += lb_size * lb_limit; + pfn_ap_logio_get_last_bytes = APR_RETRIEVE_OPTIONAL_FN(ap_logio_get_last_bytes); + return scoreboard_size; } @@ -350,11 +354,21 @@ AP_DECLARE(int) ap_exists_scoreboard_image(void) AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sb, request_rec *r) { worker_score *ws; + apr_off_t bytes; if (!sb) return; ws = &ap_scoreboard_image->servers[sb->child_num][sb->thread_num]; + if (pfn_ap_logio_get_last_bytes != NULL) { + bytes = pfn_ap_logio_get_last_bytes(r->connection); + } + else if (r->method_number == M_GET && r->method[0] == 'H') { + bytes = 0; + } + else { + bytes = r->bytes_sent; + } #ifdef HAVE_TIMES times(&ws->times); @@ -362,9 +376,9 @@ AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sb, request_rec *r) ws->access_count++; ws->my_access_count++; ws->conn_count++; - ws->bytes_served += r->bytes_sent; - ws->my_bytes_served += r->bytes_sent; - ws->conn_bytes += r->bytes_sent; + ws->bytes_served += bytes; + ws->my_bytes_served += bytes; + ws->conn_bytes += bytes; } AP_DECLARE(int) ap_find_child_by_pid(apr_proc_t *pid)