]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Alter <alter@alter.org.ua>
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 25 Jun 2008 12:21:03 +0000 (00:21 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 25 Jun 2008 12:21:03 +0000 (00:21 +1200)
Bug 2301: Regression: Log format request/reply size options

MFC: logging HTTP-request size

I've made patch to Squid 2.5-stable14 (r4), which enables logging of
http-request size and/or total request+reply size.
Patch extends 'logformat' option of squid.conf. '>st' and 'st' can be
used to log request size and total size respectively. If 'st' is used
instead of '<st', squid will log total request size
instead of reply size to access.log. For example

logformat altsquid %ts.%03tu %6tr %>a %Ss/%03Hs %st %rm %ru %un %Sh/%<A %mt
access_log /usr/local/squid/logs/access.log altsquid

src/AccessLogEntry.h
src/access_log.cc
src/cf.data.pre
src/client_side.cc
src/icp_v2.cc

index 574d684895e6621d34b836b573581d488376fefb..659aaa36600b29cb87528a75fe0d888ad6b9305b 100644 (file)
@@ -78,7 +78,8 @@ public:
 
     public:
         CacheDetails() : caddr(),
-                size(0),
+                requestSize(0),
+                replySize(0),
                 highOffset(0),
                 objectSize(0),
                 code (LOG_TAG_NONE),
@@ -93,7 +94,8 @@ public:
         }
 
         IPAddress caddr;
-        int64_t size;
+        int64_t requestSize;
+        int64_t replySize;
         int64_t highOffset;
         int64_t objectSize;
         log_type code;
index 4068cf536df12f9dcff1708f1b88db7d1afd45a8..8e43b1229ed0966e3ed72558a0dac29273481586 100644 (file)
@@ -365,7 +365,7 @@ typedef enum {
     /*LFT_REQUEST_QUERY, * // * this is not needed. see strip_query_terms */
     LFT_REQUEST_VERSION,
 
-    /*LFT_REQUEST_SIZE_TOTAL, */
+    LFT_REQUEST_SIZE_TOTAL,
     /*LFT_REQUEST_SIZE_LINE, */
     /*LFT_REQUEST_SIZE_HEADERS, */
     /*LFT_REQUEST_SIZE_BODY, */
@@ -380,6 +380,7 @@ typedef enum {
     /*LFT_REPLY_SIZE_BODY_NO_TE, */
 
     LFT_TAG,
+    LFT_IO_SIZE_TOTAL,
     LFT_EXT_LOG,
 
     LFT_PERCENT                        /* special string cases for escaped chars */
@@ -478,7 +479,7 @@ struct logformat_token_table_entry logformat_token_table[] =
         {">v", LFT_REQUEST_VERSION},
         {"rv", LFT_REQUEST_VERSION},
 
-        /*{ ">st", LFT_REQUEST_SIZE_TOTAL }, */
+        { ">st", LFT_REQUEST_SIZE_TOTAL },
         /*{ ">sl", LFT_REQUEST_SIZE_LINE }, * / / * the request line "GET ... " */
         /*{ ">sh", LFT_REQUEST_SIZE_HEADERS }, */
         /*{ ">sb", LFT_REQUEST_SIZE_BODY }, */
@@ -493,6 +494,7 @@ struct logformat_token_table_entry logformat_token_table[] =
         /*{ "<sB", LFT_REPLY_SIZE_BODY_NO_TE }, */
 
         {"et", LFT_TAG},
+        {"st", LFT_IO_SIZE_TOTAL},
         {"ea", LFT_EXT_LOG},
 
         {"%", LFT_PERCENT},
@@ -770,22 +772,22 @@ accessLogCustom(AccessLogEntry * al, customlog * log)
 
         case LFT_REQUEST_VERSION:
             snprintf(tmp, sizeof(tmp), "%d.%d", (int) al->http.version.major, (int) al->http.version.minor);
-
             out = tmp;
+            break;
 
+        case LFT_REQUEST_SIZE_TOTAL:
+            outint = al->cache.requestSize;
+            dooff = 1;
             break;
 
-            /*case LFT_REQUEST_SIZE_TOTAL: */
             /*case LFT_REQUEST_SIZE_LINE: */
             /*case LFT_REQUEST_SIZE_HEADERS: */
             /*case LFT_REQUEST_SIZE_BODY: */
             /*case LFT_REQUEST_SIZE_BODY_NO_TE: */
 
         case LFT_REPLY_SIZE_TOTAL:
-            outoff = al->cache.size;
-
+            outoff = al->cache.replySize;
             dooff = 1;
-
             break;
 
         case LFT_REPLY_HIGHOFFSET:
@@ -815,6 +817,11 @@ accessLogCustom(AccessLogEntry * al, customlog * log)
 
             break;
 
+        case LFT_IO_SIZE_TOTAL:
+            outint = al->cache.requestSize + al->cache.replySize;
+            doint = 1;
+            break;
+
         case LFT_EXT_LOG:
             if (al->request)
                 out = al->request->extacl_log.buf();
@@ -1299,7 +1306,7 @@ accessLogSquid(AccessLogEntry * al, Logfile * logfile)
                       client,
                       log_tags[al->cache.code],
                       al->http.code,
-                      al->cache.size,
+                      al->cache.replySize,
                       al->_private.method_str,
                       al->url,
                       user ? user : dash_str,
@@ -1317,7 +1324,7 @@ accessLogSquid(AccessLogEntry * al, Logfile * logfile)
                       client,
                       log_tags[al->cache.code],
                       al->http.code,
-                      al->cache.size,
+                      al->cache.replySize,
                       al->_private.method_str,
                       al->url,
                       user ? user : dash_str,
@@ -1361,7 +1368,7 @@ accessLogCommon(AccessLogEntry * al, Logfile * logfile)
                   al->url,
                   al->http.version.major, al->http.version.minor,
                   al->http.code,
-                  al->cache.size,
+                  al->cache.replySize,
                   log_tags[al->cache.code],
                   hier_strings[al->hier.code]);
 
index fb42ce112d1aa9260472492b13924095257ece88..0deeac21d414fd5b4975c44c3da550a35044ed6a 100644 (file)
@@ -2266,6 +2266,8 @@ DOC_START
                et      Tag returned by external acl
                ea      Log string returned by external acl
                <st     Reply size including HTTP headers
+               >st     Request size including HTTP headers
+               st      Request+Reply size including HTTP headers
                <sH     Reply high offset sent
                <sS     Upstream object size
                %       a literal % character
index 8b6450b282881c91be710d4dedd86b8e0148f3b7..71e06ce4ca2e435bb383625f18c6773f252e2c6b 100644 (file)
@@ -463,7 +463,7 @@ clientPrepareLogWithRequestDetails(HttpRequest * request, AccessLogEntry * aLogE
     aLogEntry->http.method = request->method;
     aLogEntry->http.version = request->http_ver;
     aLogEntry->hier = request->hier;
-
+    aLogEntry->cache.requestSize += request->content_length;
     aLogEntry->cache.extuser = request->extacl_user.buf();
 
     if (request->auth_user_request) {
@@ -501,7 +501,9 @@ ClientHttpRequest::logRequest()
 
         if(getConn() != NULL) al.cache.caddr = getConn()->log_addr;
 
-        al.cache.size = out.size;
+        al.cache.requestSize = req_sz;
+
+        al.cache.replySize = out.size;
 
         al.cache.highOffset = out.offset;
 
index 9c534ff1aa0fed80a63293e28a00464d362bac02..2c5b592cbf3140c05059d2c4e696e8137e4bf526 100644 (file)
@@ -194,7 +194,7 @@ icpLogIcp(const IPAddress &caddr, log_type logcode, int len, const char *url, in
 
     al.cache.caddr = caddr;
 
-    al.cache.size = len;
+    al.cache.replySize = len;
 
     al.cache.code = logcode;