You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2017/11/29 00:07:52 UTC

[trafficserver] 01/02: Add protocol metrics to traffic_logstats

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 4f0c3b0112957c583d64ccfbc847be2ffcfa7556
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Fri Nov 24 09:36:38 2017 +0100

    Add protocol metrics to traffic_logstats
    
    (cherry picked from commit 313508c649e0ff62dc235366c12f483b6dd76707)
---
 proxy/logstats.cc            | 42 +++++++++++++++++++++++++++++++++++++-----
 proxy/tests/logstats.json    |  4 ++++
 proxy/tests/logstats.summary |  6 ++++++
 3 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/proxy/logstats.cc b/proxy/logstats.cc
index f2f31c7..6331ea3 100644
--- a/proxy/logstats.cc
+++ b/proxy/logstats.cc
@@ -230,6 +230,11 @@ struct OriginStats {
   } schemes;
 
   struct {
+    StatsCounter ipv4;
+    StatsCounter ipv6;
+  } protocols;
+
+  struct {
     StatsCounter options;
     StatsCounter get;
     StatsCounter head;
@@ -1167,6 +1172,18 @@ update_schemes(OriginStats *stat, int scheme, int size)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
+// Update the "protocols" stats for a particular record
+inline void
+update_protocols(OriginStats *stat, bool ipv6, int size)
+{
+  if (ipv6) {
+    update_counter(stat->protocols.ipv6, size);
+  } else {
+    update_counter(stat->protocols.ipv4, size);
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////////
 // Finds or creates a stats structures if missing
 OriginStats *
 find_or_create_stats(const char *key)
@@ -1199,18 +1216,20 @@ find_or_create_stats(const char *key)
 // Update the stats
 void
 update_stats(OriginStats *o_stats, const HTTPMethod method, URLScheme scheme, int http_code, int size, int result, int hier,
-             int elapsed)
+             int elapsed, bool ipv6)
 {
   update_results_elapsed(&totals, result, elapsed, size);
   update_codes(&totals, http_code, size);
   update_methods(&totals, method, size);
   update_schemes(&totals, scheme, size);
+  update_protocols(&totals, ipv6, size);
   update_counter(totals.total, size);
   if (NULL != o_stats) {
     update_results_elapsed(o_stats, result, elapsed, size);
     update_codes(o_stats, http_code, size);
     update_methods(o_stats, method, size);
     update_schemes(o_stats, scheme, size);
+    update_protocols(o_stats, ipv6, size);
     update_counter(o_stats->total, size);
   }
 }
@@ -1238,6 +1257,7 @@ parse_log_buff(LogBufferHeader *buf_header, bool summary = false, bool aggregate
   OriginStats *o_stats;
   HTTPMethod method;
   URLScheme scheme;
+  bool ipv6;
 
   if (!fieldlist) {
     fieldlist = new LogFieldList;
@@ -1275,9 +1295,11 @@ parse_log_buff(LogBufferHeader *buf_header, bool summary = false, bool aggregate
           LogFieldIp *ip = reinterpret_cast<LogFieldIp *>(read_from);
           int len        = sizeof(LogFieldIp);
           if (AF_INET == ip->_family) {
-            len = sizeof(LogFieldIp4);
+            ipv6 = false;
+            len  = sizeof(LogFieldIp4);
           } else if (AF_INET6 == ip->_family) {
-            len = sizeof(LogFieldIp6);
+            ipv6 = true;
+            len  = sizeof(LogFieldIp6);
           }
           read_from += INK_ALIGN_DEFAULT(len);
         }
@@ -1406,7 +1428,7 @@ parse_log_buff(LogBufferHeader *buf_header, bool summary = false, bool aggregate
         }
         read_from += LogAccess::round_strlen(tok_len + 1);
         if (!aggregate_per_userid) {
-          update_stats(o_stats, method, scheme, http_code, size, result, hier, elapsed);
+          update_stats(o_stats, method, scheme, http_code, size, result, hier, elapsed, ipv6);
         }
         break;
 
@@ -1417,7 +1439,7 @@ parse_log_buff(LogBufferHeader *buf_header, bool summary = false, bool aggregate
           if (!summary) {
             o_stats = find_or_create_stats(read_from);
           }
-          update_stats(o_stats, method, scheme, http_code, size, result, hier, elapsed);
+          update_stats(o_stats, method, scheme, http_code, size, result, hier, elapsed, ipv6);
         }
 
         if ('-' == *read_from) {
@@ -2129,6 +2151,16 @@ print_detail_stats(const OriginStats *stat, bool json, bool concise)
   if (!json) {
     std::cout << std::endl << std::endl;
 
+    // Protocol familes
+    format_detail_header("Protocols");
+  }
+
+  format_line(json ? "proto.ipv4" : "IPv4", stat->protocols.ipv4, stat->total, json, concise);
+  format_line(json ? "proto.ipv6" : "IPv6", stat->protocols.ipv6, stat->total, json, concise);
+
+  if (!json) {
+    std::cout << std::endl << std::endl;
+
     // Content types
     format_detail_header("Content Types");
   }
diff --git a/proxy/tests/logstats.json b/proxy/tests/logstats.json
index 7b20d17..d9609e8 100644
--- a/proxy/tests/logstats.json
+++ b/proxy/tests/logstats.json
@@ -82,6 +82,8 @@
     "scheme.https" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "scheme.none" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "scheme.other" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
+    "proto.ipv4" : { "req": "67", "req_pct": "100.00", "bytes": "6601222", "bytes_pct": "100.00" },
+    "proto.ipv6" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "content.text.javascript" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "content.text.css" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "content.text.html" : { "req": "49", "req_pct": "73.13", "bytes": "4329503", "bytes_pct": "65.59" },
@@ -205,6 +207,8 @@
     "scheme.https" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "scheme.none" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "scheme.other" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
+    "proto.ipv4" : { "req": "67", "req_pct": "100.00", "bytes": "6601222", "bytes_pct": "100.00" },
+    "proto.ipv6" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "content.text.javascript" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "content.text.css" : { "req": "0", "req_pct": "0.00", "bytes": "0", "bytes_pct": "0.00" },
     "content.text.html" : { "req": "49", "req_pct": "73.13", "bytes": "4329503", "bytes_pct": "65.59" },
diff --git a/proxy/tests/logstats.summary b/proxy/tests/logstats.summary
index 20e1460..34a4560 100644
--- a/proxy/tests/logstats.summary
+++ b/proxy/tests/logstats.summary
@@ -111,6 +111,12 @@ none                                       0      0.00%      0.00KB      0.00%
 other                                      0      0.00%      0.00KB      0.00%
 
 
+Protocols                              Count    Percent       Bytes    Percent
+------------------------------------------------------------------------------
+IPv4                                      67    100.00%      6.30MB    100.00%
+IPv6                                       0      0.00%      0.00KB      0.00%
+
+
 Content Types                          Count    Percent       Bytes    Percent
 ------------------------------------------------------------------------------
 text/javascript                            0      0.00%      0.00KB      0.00%

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.