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);
}
std::lock_guard<std::mutex> 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++;
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);
#include <map>
#include <fstream>
-
-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<ComboAddress,int> filterScore(const map<ComboAddress, unsigned int,ComboAddress::addressOnlyLessThan >& counts,
double delta, int rate)
{
map<ComboAddress,int> ret;
double lim = delta*rate;
-
for(auto s = score.crbegin(); s != score.crend() && s->first > lim; ++s) {
ret[s->second]=s->first;
}
{
return exceedRespGen(rate, seconds, [rcode](counts_t& counts, const Rings::Response& r)
{
- if(r.rcode == rcode)
+ if(r.dh.rcode == rcode)
counts[r.requestor]++;
});
}
clock_gettime(CLOCK_MONOTONIC, &now);
std::multimap<struct timespec, string> 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;
}
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;
for(const auto& p : out) {
g_outputBuffer+=p.second;
- g_outputBuffer.append(1,'\n');
}
});
}
{
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++;
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<std::mutex> 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();
}
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
std::lock_guard<std::mutex> 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++;
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)) {
DNSName name;
uint16_t size;
uint16_t qtype;
+ struct dnsheader dh;
};
boost::circular_buffer<Query> queryRing;
struct Response
ComboAddress requestor;
DNSName name;
uint16_t qtype;
- uint8_t rcode;
unsigned int usec;
unsigned int size;
+ struct dnsheader dh;
};
boost::circular_buffer<Response> respRing;
std::mutex respMutex;
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)
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;
+}
return addS(c.size());
}
+double DiffTime(const struct timespec& first, const struct timespec& second);
+double DiffTime(const struct timeval& first, const struct timeval& second);