]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: Add a new 'backend-queries' metric
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 6 Apr 2020 13:05:37 +0000 (15:05 +0200)
committermind04 <mind04@monshouwer.org>
Tue, 27 Oct 2020 08:04:19 +0000 (09:04 +0100)
Counting the numbers of queries sent to the backend(s), instead of
relying on the number of cache misses.

pdns/dnsbackend.cc
pdns/ueberbackend.cc
pdns/ueberbackend.hh
regression-tests.nobackend/counters/command

index 12ba56b2fc4c9c66a56951feaf648f6022f4c4bc..8ead24b379e64649d9eaac4e667bd30fb1ea8f44 100644 (file)
@@ -32,6 +32,9 @@
 #include "pdns/packetcache.hh"
 #include "dnspacket.hh"
 #include "dns.hh"
+#include "statbag.hh"
+
+extern StatBag S;
 
 // this has to be somewhere central, and not in a file that requires Lua
 // this is so the geoipbackend can set this pointer if loaded for lua-record.cc
@@ -241,6 +244,7 @@ vector<DNSBackend *> BackendMakerClass::all(bool metadataOnly)
 bool DNSBackend::getSOA(const DNSName &domain, SOAData &sd)
 {
   this->lookup(QType(QType::SOA),domain,-1);
+  S.inc("backend-queries");
 
   DNSResourceRecord rr;
   rr.auth = true;
index 0a897649db909fdbe4f79edd617b03929de3c2ce..18a6e4b0be78ff9227010c5ee715edecd0939041 100644 (file)
@@ -57,6 +57,7 @@ bool UeberBackend::d_go=false;
 bool UeberBackend::s_doANYLookupsOnly=false;
 std::mutex UeberBackend::d_mut;
 std::condition_variable UeberBackend::d_cond;
+AtomicCounter* UeberBackend::s_backendQueries = nullptr;
 
 //! Loads a module and reports it to all UeberBackend threads
 bool UeberBackend::loadmodule(const string &name)
@@ -99,6 +100,9 @@ void UeberBackend::go(void)
     s_doANYLookupsOnly = true;
   }
 
+  S.declare("backend-queries", "Number of queries sent to the backend(s)");
+  s_backendQueries = S.getPointer("backend-queries");
+
   {
     std::unique_lock<std::mutex> l(d_mut);
     d_go = true;
@@ -612,6 +616,7 @@ void UeberBackend::lookup(const QType &qtype,const DNSName &qname, int zoneId, D
       d_negcached=d_cached=false;
       d_answers.clear(); 
       (d_handle.d_hinterBackend=backends[d_handle.i++])->lookup(d_handle.qtype, d_handle.qname, d_handle.zoneId, d_handle.pkt_p);
+      ++(*s_backendQueries);
     } 
     else if(cstat==0) {
       //      cout<<"UeberBackend::lookup("<<qname<<"|"<<DNSRecordContent::NumberToType(qtype.getCode())<<"): NEGcached"<<endl;
@@ -719,6 +724,7 @@ bool UeberBackend::handle::get(DNSZoneRecord &r)
       
       d_hinterBackend=parent->backends[i++];
       d_hinterBackend->lookup(qtype,qname,zoneId,pkt_p);
+      ++(*s_backendQueries);
     }
     else 
       break;
index d708569adda9b5412c73d07e0e6c3fc0190ec8e9..09149cdaca118a3efa8740eb285b513213aeb91b 100644 (file)
@@ -153,6 +153,7 @@ private:
 
   bool d_negcached;
   bool d_cached;
+  static AtomicCounter* s_backendQueries;
   static bool d_go;
   bool d_stale;
   static bool s_doANYLookupsOnly;
index 9ff54727d7c93d5dd4b2d6d70d09371cb63e49d7..91ef56e8dce57eff0cae6d870ef0b390c3b61864 100755 (executable)
@@ -27,7 +27,7 @@ $SDIG ::1 $port example.com SOA >&2 >/dev/null
 $SDIG ::1 $port example.com SOA tcp >&2 >/dev/null
 
 $PDNSCONTROL --config-name= --no-config --socket-dir=./ 'show *' | \
-  tr ',' '\n'| grep -v -E '(user-msec|sys-msec|cpu-iowait|cpu-steal|uptime|udp-noport-errors|udp-in-errors|real-memory-usage|special-memory-usage|udp-recvbuf-errors|udp-sndbuf-errors|-hit|-miss|fd-usage|latency)' | LC_ALL=C sort
+  tr ',' '\n'| grep -v -E '(user-msec|sys-msec|cpu-iowait|cpu-steal|uptime|udp-noport-errors|udp-in-errors|real-memory-usage|special-memory-usage|udp-recvbuf-errors|udp-sndbuf-errors|-hit|-miss|fd-usage|latency|backend-queries)' | LC_ALL=C sort
 
 kill $(cat pdns*.pid)
 rm pdns*.pid