From: bert hubert Date: Tue, 8 Dec 2015 15:52:18 +0000 (+0100) Subject: fix up bandwidth exceeded limits, move dnsheader (12 bytes) into ringbuffer, add... X-Git-Tag: dnsdist-1.0.0-alpha1~99^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fcaeeace8b1225bacae2bbeb21616d70f077c85;p=thirdparty%2Fpdns.git fix up bandwidth exceeded limits, move dnsheader (12 bytes) into ringbuffer, add it to grepq output, make that somewhat pretty, plus fix up TCP reporting to the response rings --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 91983ee5c3..f50beee1e7 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -748,7 +748,7 @@ vector> setupLua(bool client, const std::string& confi for(const auto& r : ring) { item["name"]=r.name.toString(); item["qtype"]=r.qtype; - item["rcode"]=r.rcode; + item["rcode"]=r.dh.rcode; item["usec"]=r.usec; ret.push_back(item); } @@ -762,7 +762,7 @@ vector> setupLua(bool client, const std::string& confi std::lock_guard lock(g_rings.respMutex); if(!labels) { for(const auto& a : g_rings.respRing) { - if(a.rcode!=kind) + if(a.dh.rcode!=kind) continue; counts[a.name]++; total++; @@ -771,7 +771,7 @@ vector> setupLua(bool client, const std::string& confi else { unsigned int lab = *labels; for(auto a : g_rings.respRing) { - if(a.rcode!=kind) + if(a.dh.rcode!=kind) continue; a.name.trimToLabels(lab); diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 40951bbbdc..0118c4ea8b 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -8,19 +8,6 @@ #include #include - -static double DiffTime(const struct timespec& first, const struct timespec& second) -{ - int seconds=second.tv_sec - first.tv_sec; - int nseconds=second.tv_nsec - first.tv_nsec; - - if(nseconds < 0) { - seconds-=1; - nseconds+=1000000000; - } - return seconds + nseconds/1000000000.0; -} - map filterScore(const map& counts, double delta, int rate) { @@ -31,7 +18,6 @@ map filterScore(const map ret; double lim = delta*rate; - for(auto s = score.crbegin(); s != score.crend() && s->first > lim; ++s) { ret[s->second]=s->first; } @@ -89,7 +75,7 @@ map exceedRCode(int rate, int seconds, int rcode) { return exceedRespGen(rate, seconds, [rcode](counts_t& counts, const Rings::Response& r) { - if(r.rcode == rcode) + if(r.dh.rcode == rcode) counts[r.requestor]++; }); } @@ -236,10 +222,14 @@ void moreLua() clock_gettime(CLOCK_MONOTONIC, &now); std::multimap out; + + boost::format fmt("%-7.1f %-47s %-5d %-25s %-5s %-4.1f %-2s %-2s %-2s %s\n"); + g_outputBuffer+= (fmt % "Time" % "Client" % "ID" % "Name" % "Type" % "Lat." % "TC" % "RD" % "AA" % "Rcode").str(); + for(const auto& c : qr) { if((nm && nm->match(c.requestor)) || (dn && c.name.isPartOf(*dn))) { QType qt(c.qtype); - out.insert(make_pair(c.when,std::to_string(DiffTime(now, c.when))+'\t'+c.requestor.toStringWithPort() +'\t'+c.name.toString() + '\t' + qt.getName())); + out.insert(make_pair(c.when, (fmt % DiffTime(now, c.when) % c.requestor.toStringWithPort() % htons(c.dh.id) % c.name.toString() % qt.getName() % "" % (c.dh.tc ? "TC" : "") % (c.dh.rd? "RD" : "") % (c.dh.aa? "AA" : "") % "Question").str() )) ; if(limit && *limit==++num) break; @@ -247,10 +237,12 @@ void moreLua() } num=0; + + for(const auto& c : rr) { if((nm && nm->match(c.requestor)) || (dn && c.name.isPartOf(*dn))) { QType qt(c.qtype); - out.insert(make_pair(c.when,std::to_string(DiffTime(now, c.when))+'\t'+c.requestor.toStringWithPort() +'\t'+c.name.toString() + '\t' + qt.getName()+'\t' + std::to_string(c.usec/1000.0) + '\t'+ RCode::to_s(c.rcode))); + out.insert(make_pair(c.when, (fmt % DiffTime(now, c.when) % c.requestor.toStringWithPort() % htons(c.dh.id) % c.name.toString() % qt.getName() % (c.usec/1000.0) % (c.dh.tc ? "TC" : "") % (c.dh.rd? "RD" : "") % (c.dh.aa? "AA" : "") % RCode::to_s(c.dh.rcode)).str() )) ; if(limit && *limit==++num) break; @@ -259,7 +251,6 @@ void moreLua() for(const auto& p : out) { g_outputBuffer+=p.second; - g_outputBuffer.append(1,'\n'); } }); } diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 60936ad788..e1766e1eed 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -174,7 +174,7 @@ void* tcpClientThread(int pipefd) { WriteLock wl(&g_rings.queryLock); - g_rings.queryRing.push_back({now,ci.remote,qname,qtype}); + g_rings.queryRing.push_back({now,ci.remote,qname,(uint16_t)queryLen,qtype,*dh}); } g_stats.queries++; @@ -370,7 +370,14 @@ void* tcpClientThread(int pipefd) writen2WithTimeout(ci.fd, response, responseLen, ds->tcpSendTimeout); g_stats.responses++; - + struct timespec answertime; + clock_gettime(CLOCK_MONOTONIC, &answertime); + unsigned int udiff = 1000000.0*DiffTime(now,answertime); + { + std::lock_guard lock(g_rings.respMutex); + g_rings.respRing.push_back({answertime, ci.remote, qname, qtype, (unsigned int)udiff, (unsigned int)responseLen, *dh}); + } + largerQuery.clear(); rewrittenResponse.clear(); } diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 87aaf47036..a40d37eb9e 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -233,7 +233,7 @@ void* responderThread(std::shared_ptr state) struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); std::lock_guard lock(g_rings.respMutex); - g_rings.respRing.push_back({ts, ids->origRemote, ids->qname, ids->qtype, (uint8_t)dh->rcode, (unsigned int)udiff, (unsigned int)len}); + g_rings.respRing.push_back({ts, ids->origRemote, ids->qname, ids->qtype, (unsigned int)udiff, (unsigned int)len, *dh}); } if(dh->rcode == RCode::ServFail) g_stats.servfailResponses++; @@ -516,7 +516,7 @@ try clock_gettime(CLOCK_MONOTONIC, &now); { WriteLock wl(&g_rings.queryLock); - g_rings.queryRing.push_back({now,remote,qname,(uint16_t)len,qtype}); + g_rings.queryRing.push_back({now,remote,qname,(uint16_t)len,qtype, *dh}); } if(auto got=localDynBlock->lookup(remote)) { diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index c48fda1c5e..c2178abd37 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -212,6 +212,7 @@ struct Rings { DNSName name; uint16_t size; uint16_t qtype; + struct dnsheader dh; }; boost::circular_buffer queryRing; struct Response @@ -220,9 +221,9 @@ struct Rings { ComboAddress requestor; DNSName name; uint16_t qtype; - uint8_t rcode; unsigned int usec; unsigned int size; + struct dnsheader dh; }; boost::circular_buffer respRing; std::mutex respMutex; diff --git a/pdns/dnsreplay.cc b/pdns/dnsreplay.cc index 2ace0421f8..266a0734fa 100644 --- a/pdns/dnsreplay.cc +++ b/pdns/dnsreplay.cc @@ -203,17 +203,6 @@ unsigned int s_webetter, s_origbetter, s_norecursionavailable; unsigned int s_weunmatched, s_origunmatched; unsigned int s_wednserrors, s_origdnserrors, s_duplicates; -static double DiffTime(const struct timeval& first, const struct timeval& second) -{ - int seconds=second.tv_sec - first.tv_sec; - int useconds=second.tv_usec - first.tv_usec; - - if(useconds < 0) { - seconds-=1; - useconds+=1000000; - } - return seconds + useconds/1000000.0; -} void WeOrigSlowQueriesDelta(int& weOutstanding, int& origOutstanding, int& weSlow, int& origSlow) diff --git a/pdns/misc.cc b/pdns/misc.cc index 61c64f9fe9..b2ee147ba9 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -1208,3 +1208,27 @@ uint64_t getCPUTimeSystem(const std::string&) getrusage(RUSAGE_SELF, &ru); return (ru.ru_stime.tv_sec*1000ULL + ru.ru_stime.tv_usec/1000); } + +double DiffTime(const struct timespec& first, const struct timespec& second) +{ + int seconds=second.tv_sec - first.tv_sec; + int nseconds=second.tv_nsec - first.tv_nsec; + + if(nseconds < 0) { + seconds-=1; + nseconds+=1000000000; + } + return seconds + nseconds/1000000000.0; +} + +double DiffTime(const struct timeval& first, const struct timeval& second) +{ + int seconds=second.tv_sec - first.tv_sec; + int useconds=second.tv_usec - first.tv_usec; + + if(useconds < 0) { + seconds-=1; + useconds+=1000000; + } + return seconds + useconds/1000000.0; +} diff --git a/pdns/misc.hh b/pdns/misc.hh index eb1dbd4482..9036bb2d63 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -645,3 +645,5 @@ const char* addS(const C& c, typename std::enable_if::value>::t return addS(c.size()); } +double DiffTime(const struct timespec& first, const struct timespec& second); +double DiffTime(const struct timeval& first, const struct timeval& second);