]> granicus.if.org Git - pdns/commitdiff
implement somewhat finegrained statistics
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 29 Mar 2015 13:32:19 +0000 (15:32 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 29 Mar 2015 13:32:19 +0000 (15:32 +0200)
pdns/dnsdist-lua.cc
pdns/dnsdist.cc
pdns/dnsdist.hh

index 6982f445836a7d9207fe2c022ab8d8d309cd2ab9..2e99c633830278767fd525aa56cea5129b0d3125 100644 (file)
@@ -14,6 +14,7 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
 {
   g_launchWork= new vector<std::function<void(void)>>();
   typedef std::unordered_map<std::string, boost::variant<std::string, vector<pair<int, std::string> > > > newserver_t;
+
   g_lua.writeFunction("newServer", 
                      [client](boost::variant<string,newserver_t> pvars, boost::optional<int> qps)
                      { 
index 7f2f40c326b9b3a93ff76a83a16164c8ab1ddc4d..4b0f8d55821ea9a99bed15641291f590048d2ce9 100644 (file)
 #include "dnsrulactions.hh"
 
 #include <getopt.h>
-#undef L
 
 /* Known sins:
-   No centralized statistics
+
    Receiver is currently singlethreaded
       not *that* bad actually, but now that we are thread safe, might want to scale
    TCP is a bit wonky and may pick the wrong downstream
@@ -57,8 +56,8 @@
 using std::atomic;
 using std::thread;
 bool g_verbose;
-atomic<uint64_t> g_pos;
 
+struct DNSDistStats g_stats;
 uint16_t g_maxOutstanding;
 bool g_console;
 
@@ -127,7 +126,7 @@ void* responderThread(std::shared_ptr<DownstreamState> state)
       --state->outstanding;  // you'd think an attacker could game this, but we're using connected socket
 
     dh->id = ids->origID;
-    
+    g_stats.responses++;
     if(ids->origDest.sin4.sin_family == 0)
       sendto(ids->origFD, packet, len, 0, (struct sockaddr*)&ids->origRemote, ids->origRemote.getSocklen());
     else
@@ -135,9 +134,12 @@ void* responderThread(std::shared_ptr<DownstreamState> state)
     double udiff = ids->sentTime.udiff();
     vinfolog("Got answer from %s, relayed to %s, took %f usec", state->remote.toStringWithPort(), ids->origRemote.toStringWithPort(), udiff);
 
-    std::lock_guard<std::mutex> lock(g_rings.respMutex);
-    g_rings.respRing.push_back({ids->qname, ids->qtype, (uint8_t)dh->rcode, (unsigned int)udiff});
-    
+    {
+      std::lock_guard<std::mutex> lock(g_rings.respMutex);
+      g_rings.respRing.push_back({ids->qname, ids->qtype, (uint8_t)dh->rcode, (unsigned int)udiff});
+    }
+    if(dh->rcode == 2)
+      g_stats.servfailResponses++;
     state->latencyUsec = (127.0 * state->latencyUsec / 128.0) + udiff/128.0;
 
     ids->origFD = -1;
@@ -332,8 +334,11 @@ try
       if(len < (int)sizeof(struct dnsheader)) 
        continue;
 
-      if(!acl->match(remote))
+      g_stats.queries++;
+      if(!acl->match(remote)) {
+       g_stats.aclDrops++;
        continue;
+      }
       
       if(dh->qr)    // don't respond to responses
        continue;
@@ -346,8 +351,10 @@ try
       if(blockFilter) {
        std::lock_guard<std::mutex> lock(g_luamutex);
        
-       if(blockFilter(remote, qname, qtype, dh))
+       if(blockFilter(remote, qname, qtype, dh)) {
+         g_stats.blockFilter++;
          continue;
+       }
       }
       
 
@@ -365,10 +372,12 @@ try
       }
       switch(action) {
       case DNSAction::Action::Drop:
+       g_stats.ruleDrop++;
        continue;
       case DNSAction::Action::Nxdomain:
        dh->rcode = RCode::NXDomain;
        dh->qr=true;
+       g_stats.ruleNXDomain++;
        break;
       case DNSAction::Action::Pool: 
        pool=ruleresult;
@@ -385,6 +394,7 @@ try
       }
 
       if(dh->qr) { // something turned it into a response
+       g_stats.selfAnswered++;
        ComboAddress dest;
        if(HarvestDestinationAddress(&msgh, &dest)) 
          sendfromto(cs->udpFD, packet, len, 0, dest, remote);
@@ -412,8 +422,10 @@ try
       
       if(ids->origFD < 0) // if we are reusing, no change in outstanding
        ss->outstanding++;
-      else
+      else {
        ss->reuseds++;
+       g_stats.downstreamTimeouts++;
+      }
       
       ids->origFD = cs->udpFD;
       ids->age = 0;
@@ -428,8 +440,10 @@ try
       dh->id = idOffset;
       
       len = send(ss->fd, packet, len, 0);
-      if(len < 0) 
+      if(len < 0) {
        ss->sendErrors++;
+       g_stats.downstreamSendErrors++;
+      }
       
       vinfolog("Got query from %s, relayed to %s", remote.toStringWithPort(), ss->remote.toStringWithPort());
     }
index abf6cdd7ffffd08355d1b2874ad2e6eac74e41ab..c84a72e07879f7a9ce6fa5735bc44bca7cabb3ed 100644 (file)
 #include <thread>
 #include "sholder.hh"
 
+struct DNSDistStats
+{
+  using stat_t=std::atomic<uint64_t>;
+  stat_t responses{0};
+  stat_t servfailResponses{0};
+  stat_t queries{0};
+  stat_t aclDrops{0};
+  stat_t blockFilter{0};
+  stat_t ruleDrop{0};
+  stat_t ruleNXDomain{0};
+  stat_t selfAnswered{0};
+  stat_t downstreamTimeouts{0};
+  stat_t downstreamSendErrors{0};
+  
+};
+
+extern struct DNSDistStats g_stats;
+
 
 struct StopWatch
 {