From: bert hubert Date: Sat, 15 Mar 2014 20:58:15 +0000 (+0100) Subject: add some infrastructure for outputting per second statistics X-Git-Tag: rec-3.6.0-rc1~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad79b1b52cb5be72e2876e1d535bee7d049defd5;p=thirdparty%2Fpdns.git add some infrastructure for outputting per second statistics --- diff --git a/pdns/dnsscope.cc b/pdns/dnsscope.cc index 60704a0041..ab30fcfa68 100644 --- a/pdns/dnsscope.cc +++ b/pdns/dnsscope.cc @@ -35,6 +35,39 @@ struct QuestionData typedef map statmap_t; statmap_t statmap; +unsigned int liveQuestions() +{ + unsigned int ret=0; + BOOST_FOREACH(statmap_t::value_type& val, statmap) { + if(!val.second.d_answercount) + ret++; + // if(val.second.d_qcount > val.second.d_answercount) + // ret+= val.second.d_qcount - val.second.d_answercount; + } + return ret; +} + +struct LiveCounts +{ + unsigned int questions; + unsigned int answers; + unsigned int outstanding; + + LiveCounts() + { + questions=answers=outstanding=0; + } + + LiveCounts operator-(const LiveCounts& rhs) + { + LiveCounts ret; + ret.questions = questions - rhs.questions; + ret.answers = answers - rhs.answers; + ret.outstanding = outstanding; + return ret; + } +}; + int main(int argc, char** argv) try { @@ -73,7 +106,10 @@ try if(g_vm.count("rd")) { rdFilter = g_vm["rd"].as(); haveRDFilter=1; + cout<<"Filtering on recursion desired="<(); bool doIPv6 = g_vm["ipv6"].as(); @@ -89,12 +125,16 @@ try cumul_t cumul; unsigned int untracked=0, errorresult=0, reallylate=0, nonRDQueries=0, queries=0; unsigned int ipv4Packets=0, ipv6Packets=0, fragmented=0; + unsigned int questions=0, answers=0; typedef map rcodes_t; rcodes_t rcodes; time_t lowestTime=2000000000, highestTime=0; - + time_t lastsec=0; + LiveCounts lastcounts; + typedef vector > pcounts_t; + pcounts_t pcounts; while(pr.getUDPPacket()) { if((ntohs(pr.d_udp->uh_dport)==5300 || ntohs(pr.d_udp->uh_sport)==5300 || ntohs(pr.d_udp->uh_dport)==53 || ntohs(pr.d_udp->uh_sport)==53) && @@ -102,7 +142,7 @@ try try { if((pr.d_ip->ip_v == 4 && !doIPv4) || (pr.d_ip->ip_v == 6 && !doIPv6)) continue; - if(pr.d_ip->ip_v ==4) { + if(pr.d_ip->ip_v == 4) { uint16_t frag = ntohs(pr.d_ip->ip_off); if((frag & IP_MF) || (frag & IP_OFFMASK)) { // more fragments or IS a fragment fragmented++; @@ -118,6 +158,21 @@ try else ++ipv6Packets; + if(pr.d_pheader.ts.tv_sec != lastsec) { + LiveCounts lc; + if(lastsec) { + lc.questions = questions; + lc.answers = answers; + lc.outstanding = liveQuestions(); + + LiveCounts diff = lc - lastcounts; + pcounts.push_back(make_pair(pr.d_pheader.ts.tv_sec, diff)); + + } + lastsec = pr.d_pheader.ts.tv_sec; + lastcounts = lc; + } + if(!mdp.d_header.qr) { if(!mdp.d_header.rd) nonRDQueries++; @@ -131,23 +186,23 @@ try QuestionIdentifier qi=QuestionIdentifier::create(pr.getSource(), pr.getDest(), mdp); - if(!mdp.d_header.qr) { - // cout<<"Question for '"<< name <<"'\n"; - + if(!mdp.d_header.qr) { // question QuestionData& qd=statmap[qi]; if(!qd.d_firstquestiontime.tv_sec) qd.d_firstquestiontime=pr.d_pheader.ts; qd.d_qcount++; + questions++; } else { // NO ERROR or NXDOMAIN + answers++; QuestionData& qd=statmap[qi]; if(!qd.d_qcount) untracked++; qd.d_answercount++; - // cout<<"Answer to '"<< name <<"': RCODE="<<(int)mdp.d_rcode<<", "<second.d_answercount) { unanswered++; - // cout << i->first.d_qname <<" " <first.d_qtype<first.d_source.toStringWithPort()<<' ' <first.d_dest.toStringWithPort()<<' '<first.d_id<<' '<first.d_qname <<" " <first.d_qtype<< " "<second.d_qcount <<" " <second.d_answercount<