Skip to content

Commit f06d069

Browse files
ahupowerdnsmind04
authored andcommitted
make latency & qsize reporting 'live'. Plus fix that we only reported the qsize of the first distributor.
1 parent 2f3498e commit f06d069

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

pdns/common_startup.cc

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "secpoll-auth.hh"
2525
#include <sys/time.h>
2626
#include <sys/resource.h>
27-
27+
#include <boost/foreach.hpp>
2828

2929
bool g_anyToTcp;
3030
typedef Distributor<DNSPacket,DNSPacket,PacketHandler> DNSDistributor;
@@ -38,6 +38,7 @@ CommunicatorClass Communicator;
3838
UDPNameserver *N;
3939
int avg_latency;
4040
TCPNameserver *TN;
41+
vector<DNSDistributor*> g_distributors;
4142

4243
ArgvMap &arg()
4344
{
@@ -185,6 +186,22 @@ static uint64_t getSysUserTimeMsec(const std::string& str)
185186

186187
}
187188

189+
static uint64_t getQCount(const std::string& str)
190+
{
191+
int totcount=0;
192+
BOOST_FOREACH(DNSDistributor* d, g_distributors) {
193+
int qcount, acount;
194+
d->getQueueSizes(qcount, acount); // this does locking and other things, so don't get smart
195+
totcount+=qcount;
196+
}
197+
return totcount;
198+
}
199+
200+
static uint64_t getLatency(const std::string& str)
201+
{
202+
return avg_latency;
203+
}
204+
188205
void declareStats(void)
189206
{
190207
S.declare("udp-queries","Number of UDP queries received");
@@ -206,7 +223,7 @@ void declareStats(void)
206223
S.declare("tcp-queries","Number of TCP queries received");
207224
S.declare("tcp-answers","Number of answers sent out over TCP");
208225

209-
S.declare("qsize-q","Number of questions waiting for database attention");
226+
S.declare("qsize-q","Number of questions waiting for database attention", getQCount);
210227

211228
S.declare("deferred-cache-inserts","Amount of cache inserts that were deferred because of maintenance");
212229
S.declare("deferred-cache-lookup","Amount of cache lookups that were deferred because of maintenance");
@@ -227,7 +244,7 @@ void declareStats(void)
227244
S.declare("signature-cache-size", "Number of entries in the signature cache", signatureCacheSize);
228245

229246
S.declare("servfail-packets","Number of times a server-failed packet was sent out");
230-
S.declare("latency","Average number of microseconds needed to answer a question");
247+
S.declare("latency","Average number of microseconds needed to answer a question", getLatency);
231248
S.declare("timedout-packets","Number of packets which weren't answered within timeout set");
232249
S.declare("security-status", "Security status based on regular polling");
233250
S.declareRing("queries","UDP Queries Received");
@@ -268,6 +285,7 @@ void *qthread(void *number)
268285
{
269286
DNSPacket *P;
270287
DNSDistributor *distributor = DNSDistributor::Create(::arg().asNum("distributor-threads", 1)); // the big dispatcher!
288+
g_distributors.push_back(distributor);
271289
DNSPacket question;
272290
DNSPacket cached;
273291

@@ -282,7 +300,6 @@ void *qthread(void *number)
282300
bool logDNSQueries = ::arg().mustDo("log-dns-queries");
283301
bool doRecursion = ::arg().mustDo("recursor");
284302
bool skipfirst=true;
285-
unsigned int maintcount = 0;
286303
UDPNameserver *NS = N;
287304

288305
// If we have SO_REUSEPORT then create a new port for all receiver threads
@@ -303,15 +320,6 @@ void *qthread(void *number)
303320
else
304321
numreceived++;
305322

306-
if(number==0) { // only run on main thread
307-
if(!((maintcount++)%250)) { // maintenance tasks - this can conceivably run infrequently
308-
S.set("latency",(int)avg_latency);
309-
int qcount, acount;
310-
distributor->getQueueSizes(qcount, acount); // this does locking and other things, so don't get smart
311-
S.set("qsize-q",qcount);
312-
}
313-
}
314-
315323
if(!(P=NS->receive(&question))) { // receive a packet inline
316324
continue; // packet was broken, try again
317325
}

0 commit comments

Comments
 (0)