24
24
#include " secpoll-auth.hh"
25
25
#include < sys/time.h>
26
26
#include < sys/resource.h>
27
-
27
+ # include < boost/foreach.hpp >
28
28
29
29
bool g_anyToTcp;
30
30
typedef Distributor<DNSPacket,DNSPacket,PacketHandler> DNSDistributor;
@@ -38,6 +38,7 @@ CommunicatorClass Communicator;
38
38
UDPNameserver *N;
39
39
int avg_latency;
40
40
TCPNameserver *TN;
41
+ vector<DNSDistributor*> g_distributors;
41
42
42
43
ArgvMap &arg ()
43
44
{
@@ -185,6 +186,22 @@ static uint64_t getSysUserTimeMsec(const std::string& str)
185
186
186
187
}
187
188
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
+
188
205
void declareStats (void )
189
206
{
190
207
S.declare (" udp-queries" ," Number of UDP queries received" );
@@ -206,7 +223,7 @@ void declareStats(void)
206
223
S.declare (" tcp-queries" ," Number of TCP queries received" );
207
224
S.declare (" tcp-answers" ," Number of answers sent out over TCP" );
208
225
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 );
210
227
211
228
S.declare (" deferred-cache-inserts" ," Amount of cache inserts that were deferred because of maintenance" );
212
229
S.declare (" deferred-cache-lookup" ," Amount of cache lookups that were deferred because of maintenance" );
@@ -227,7 +244,7 @@ void declareStats(void)
227
244
S.declare (" signature-cache-size" , " Number of entries in the signature cache" , signatureCacheSize);
228
245
229
246
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 );
231
248
S.declare (" timedout-packets" ," Number of packets which weren't answered within timeout set" );
232
249
S.declare (" security-status" , " Security status based on regular polling" );
233
250
S.declareRing (" queries" ," UDP Queries Received" );
@@ -268,6 +285,7 @@ void *qthread(void *number)
268
285
{
269
286
DNSPacket *P;
270
287
DNSDistributor *distributor = DNSDistributor::Create (::arg ().asNum (" distributor-threads" , 1 )); // the big dispatcher!
288
+ g_distributors.push_back (distributor);
271
289
DNSPacket question;
272
290
DNSPacket cached;
273
291
@@ -282,7 +300,6 @@ void *qthread(void *number)
282
300
bool logDNSQueries = ::arg ().mustDo (" log-dns-queries" );
283
301
bool doRecursion = ::arg ().mustDo (" recursor" );
284
302
bool skipfirst=true ;
285
- unsigned int maintcount = 0 ;
286
303
UDPNameserver *NS = N;
287
304
288
305
// If we have SO_REUSEPORT then create a new port for all receiver threads
@@ -303,15 +320,6 @@ void *qthread(void *number)
303
320
else
304
321
numreceived++;
305
322
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
-
315
323
if (!(P=NS->receive (&question))) { // receive a packet inline
316
324
continue ; // packet was broken, try again
317
325
}
0 commit comments