]> granicus.if.org Git - apache/commitdiff
mod_logio: introduce new optional function ap_logio_get_last_bytes to get
authorStefan Fritsch <sf@apache.org>
Thu, 8 Oct 2009 21:42:13 +0000 (21:42 +0000)
committerStefan Fritsch <sf@apache.org>
Thu, 8 Oct 2009 21:42:13 +0000 (21:42 +0000)
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

CHANGES
include/ap_mmn.h
include/http_core.h
modules/loggers/mod_logio.c
server/scoreboard.c

diff --git a/CHANGES b/CHANGES
index ef5c5c8916571234074fd77ad98276eb2844d752..7abfc2b9490ca4d86366d468740b2ab8a1a7d0ed 100644 (file)
--- 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 <sf fritsch.de>, 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
index d505475dfa87dd69740a61e5937a71da0e665281..4641f348afd4c125a059b0a7218c28e055f6cd31 100644 (file)
  * 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
index da4b8e6c80fc1239e0f7a7a62ddaaa708e456353..2583493609f496089a56197dcea2d4c9f1da6d94 100644 (file)
@@ -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
index fa8dc2178f7dae8c0a0adffd8b4b5119f666bc00..6de18a20b48d511ae6161a96565112357b6f3f7d 100644 (file)
@@ -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 =
index a1a3dbb7dbb2001002b397b88aa8db163c9d8623..0831b6351c7bf480c7a71730450fe70709dd2152 100644 (file)
@@ -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)