]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add the number of received bytes to StatNode entries 8529/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 13 Nov 2019 15:32:50 +0000 (16:32 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 13 Nov 2019 15:32:50 +0000 (16:32 +0100)
pdns/dnsdist-dynblocks.hh
pdns/dnsdist-lua-inspection.cc
pdns/dnsdistdist/dnsdist-lua-inspection-ffi.cc
pdns/dnsdistdist/dnsdist-lua-inspection-ffi.hh
pdns/dnsscope.cc
pdns/statnode.cc
pdns/statnode.hh

index dd834a1655bbb41776fb9b4e061cff6c3112e430..3dc8b5e3e0ab095c8575dfe6d9343f166a5edfd7 100644 (file)
@@ -576,7 +576,7 @@ private:
         }
 
         if (suffixMatchRuleMatches) {
-          root.submit(c.name, ((c.dh.rcode == 0 && c.usec == std::numeric_limits<unsigned int>::max()) ? -1 : c.dh.rcode), boost::none);
+          root.submit(c.name, ((c.dh.rcode == 0 && c.usec == std::numeric_limits<unsigned int>::max()) ? -1 : c.dh.rcode), c.size, boost::none);
         }
       }
     }
index 80bceee030437063af9c4e0fd4e706dd0e3e6112..c1f0a1cb801dff34a61d5dc582f5f7d4d6a1a835 100644 (file)
@@ -117,7 +117,7 @@ static void statNodeRespRing(statvisitor_t visitor, unsigned int seconds)
       if (seconds && c.when < cutoff)
         continue;
 
-      root.submit(c.name, ((c.dh.rcode == 0 && c.usec == std::numeric_limits<unsigned int>::max()) ? -1 : c.dh.rcode), boost::none);
+      root.submit(c.name, ((c.dh.rcode == 0 && c.usec == std::numeric_limits<unsigned int>::max()) ? -1 : c.dh.rcode), c.size, boost::none);
     }
   }
 
@@ -708,6 +708,7 @@ void setupLuaInspection()
   g_lua.registerMember("queries", &StatNode::Stat::queries);
   g_lua.registerMember("noerrors", &StatNode::Stat::noerrors);
   g_lua.registerMember("drops", &StatNode::Stat::drops);
+  g_lua.registerMember("bytes", &StatNode::Stat::bytes);
 
   g_lua.writeFunction("statNodeRespRing", [](statvisitor_t visitor, boost::optional<unsigned int> seconds) {
       statNodeRespRing(visitor, seconds ? *seconds : 0);
index d05882a19b6aa27d964b60577959fc8c366ac0b9..e4ebea66c4c77aa9cbc16795d16ddb0d45e7ef19 100644 (file)
@@ -48,6 +48,11 @@ uint64_t dnsdist_ffi_stat_node_get_drops_count(const dnsdist_ffi_stat_node_t* no
   return node->self.drops;
 }
 
+uint64_t dnsdist_ffi_stat_node_get_bytes(const dnsdist_ffi_stat_node_t* node)
+{
+  return node->self.bytes;
+}
+
 unsigned int dnsdist_ffi_stat_node_get_labels_count(const dnsdist_ffi_stat_node_t* node)
 {
   return node->node.labelsCount;
@@ -89,3 +94,8 @@ uint64_t dnsdist_ffi_stat_node_get_children_drops_count(const dnsdist_ffi_stat_n
 {
   return node->children.drops;
 }
+
+uint64_t dnsdist_ffi_stat_node_get_children_bytes_count(const dnsdist_ffi_stat_node_t* node)
+{
+  return node->children.bytes;
+}
index c4329a25b289b56a73ea38376a16e46e3c12de73..2b81c60b20913db775fdd20d2d87f3d6c1d8bdeb 100644 (file)
@@ -28,6 +28,7 @@ extern "C" {
   uint64_t dnsdist_ffi_stat_node_get_nxdomains_count(const dnsdist_ffi_stat_node_t* node) __attribute__ ((visibility ("default")));
   uint64_t dnsdist_ffi_stat_node_get_servfails_count(const dnsdist_ffi_stat_node_t* node) __attribute__ ((visibility ("default")));
   uint64_t dnsdist_ffi_stat_node_get_drops_count(const dnsdist_ffi_stat_node_t* node) __attribute__ ((visibility ("default")));
+  uint64_t dnsdist_ffi_stat_node_get_bytes(const dnsdist_ffi_stat_node_t* node) __attribute__ ((visibility ("default")));
   unsigned int dnsdist_ffi_stat_node_get_labels_count(const dnsdist_ffi_stat_node_t* node) __attribute__ ((visibility ("default")));
   void dnsdist_ffi_stat_node_get_full_name_raw(const dnsdist_ffi_stat_node_t* node, const char** name, size_t* nameSize) __attribute__ ((visibility ("default")));
 
@@ -38,4 +39,5 @@ extern "C" {
   uint64_t dnsdist_ffi_stat_node_get_children_nxdomains_count(const dnsdist_ffi_stat_node_t* node) __attribute__ ((visibility ("default")));
   uint64_t dnsdist_ffi_stat_node_get_children_servfails_count(const dnsdist_ffi_stat_node_t* node) __attribute__ ((visibility ("default")));
   uint64_t dnsdist_ffi_stat_node_get_children_drops_count(const dnsdist_ffi_stat_node_t* node) __attribute__ ((visibility ("default")));
+  uint64_t dnsdist_ffi_stat_node_get_children_bytes(const dnsdist_ffi_stat_node_t* node) __attribute__ ((visibility ("default")));
 }
index ce399f663aec8a87b5de0f7c7cbfb9d4d711d7b7..d30c08efa140e1159ba4341d4def726ea98c36a0 100644 (file)
@@ -359,7 +359,7 @@ try
              rem.sin4.sin_port=0;
 
              if(doServFailTree)
-               root.submit(qname, header.rcode, rem);
+               root.submit(qname, header.rcode, pr.d_len, rem);
            }
 
            if(!qd.d_qcount || qd.d_qcount == qd.d_answercount) {
index 1557bbbd6011ad1682f78181188abbf975bf8c07..00dad2afbd762cf5f3ddf911ea5be91740ba44a9 100644 (file)
@@ -12,6 +12,8 @@ StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) co
   childstat.nxdomains += s.nxdomains;
   childstat.servfails += s.servfails;
   childstat.drops += s.drops;
+  childstat.bytes += s.bytes;
+
   if(children.size()>1024 && !silent) {
     cout<<string(depth, ' ')<<name<<": too many to print"<<endl;
   }
@@ -23,7 +25,8 @@ StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) co
       childstat.noerrors<<" noerrors, "<< 
       childstat.nxdomains<<" nxdomains, "<< 
       childstat.servfails<<" servfails, "<< 
-      childstat.drops<<" drops"<<endl;
+      childstat.drops<<" drops, "<<
+      childstat.bytes<<" bytes"<<endl;
 
   newstat+=childstat;
 
@@ -39,6 +42,7 @@ void  StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) cons
   childstat.nxdomains += s.nxdomains;
   childstat.servfails += s.servfails;
   childstat.drops += s.drops;
+  childstat.bytes += s.bytes;
   childstat.remotes = s.remotes;
   
   Stat selfstat(childstat);
@@ -53,7 +57,7 @@ void  StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) cons
 }
 
 
-void StatNode::submit(const DNSName& domain, int rcode, boost::optional<const ComboAddress&> remote)
+void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, boost::optional<const ComboAddress&> remote)
 {
   //  cerr<<"FIRST submit called on '"<<domain<<"'"<<endl;
   std::vector<string> tmp = domain.getRawLabels();
@@ -61,7 +65,7 @@ void StatNode::submit(const DNSName& domain, int rcode, boost::optional<const Co
     return;
 
   auto last = tmp.end() - 1;
-  children[*last].submit(last, tmp.begin(), "", rcode, remote, 1);
+  children[*last].submit(last, tmp.begin(), "", rcode, bytes, remote, 1);
 }
 
 /* www.powerdns.com. -> 
@@ -71,7 +75,7 @@ void StatNode::submit(const DNSName& domain, int rcode, boost::optional<const Co
    www.powerdns.com. 
 */
 
-void StatNode::submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, boost::optional<const ComboAddress&> remote, unsigned int count)
+void StatNode::submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, boost::optional<const ComboAddress&> remote, unsigned int count)
 {
   //  cerr<<"Submit called for domain='"<<domain<<"': ";
   //  for(const std::string& n :  labels) 
@@ -93,6 +97,7 @@ void StatNode::submit(std::vector<string>::const_iterator end, std::vector<strin
     }
     //    cerr<<"Hit the end, set our fullname to '"<<fullname<<"'"<<endl<<endl;
     s.queries++;
+    s.bytes += bytes;
     if(rcode<0)
       s.drops++;
     else if(rcode==0)
@@ -113,7 +118,7 @@ void StatNode::submit(std::vector<string>::const_iterator end, std::vector<strin
     }
     //    cerr<<"Not yet end, set our fullname to '"<<fullname<<"', recursing"<<endl;
     --end;
-    children[*end].submit(end, begin, fullname, rcode, remote, count+1);
+    children[*end].submit(end, begin, fullname, rcode, bytes, remote, count+1);
   }
 }
 
index ac8d78cb3035febf0d8446518c267a55bde5a4d2..0f3b0e4c22f700a477e8d188080f2b9a90652c83 100644 (file)
@@ -31,8 +31,10 @@ public:
 
   struct Stat
   {
-    Stat() : queries(0), noerrors(0), nxdomains(0), servfails(0), drops(0){}
-    uint64_t queries, noerrors, nxdomains, servfails, drops;
+    Stat(): queries(0), noerrors(0), nxdomains(0), servfails(0), drops(0), bytes(0)
+    {
+    }
+    uint64_t queries, noerrors, nxdomains, servfails, drops, bytes;
 
     Stat& operator+=(const Stat& rhs) {
       queries+=rhs.queries;
@@ -40,6 +42,7 @@ public:
       nxdomains+=rhs.nxdomains;
       servfails+=rhs.servfails;
       drops+=rhs.drops;
+      bytes+=rhs.bytes;
 
       for(const remotes_t::value_type& rem : rhs.remotes) {
         remotes[rem.first]+=rem.second;
@@ -55,7 +58,7 @@ public:
   std::string fullname;
   unsigned int labelsCount{0};
 
-  void submit(const DNSName& domain, int rcode, boost::optional<const ComboAddress&> remote);
+  void submit(const DNSName& domain, int rcode, unsigned int bytes, boost::optional<const ComboAddress&> remote);
 
   Stat print(unsigned int depth=0, Stat newstat=Stat(), bool silent=false) const;
   typedef boost::function<void(const StatNode*, const Stat& selfstat, const Stat& childstat)> visitor_t;
@@ -68,5 +71,5 @@ public:
   children_t children;
 
 private:
-  void submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, boost::optional<const ComboAddress&> remote, unsigned int count);
+  void submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, boost::optional<const ComboAddress&> remote, unsigned int count);
 };