]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
make dnsgram emit 10ms-granularity query/respnse statistics on 'rdqaplot'
authorbert hubert <bert.hubert@netherlabs.nl>
Tue, 3 Mar 2015 09:49:52 +0000 (10:49 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Tue, 3 Mar 2015 09:49:52 +0000 (10:49 +0100)
pdns/dnsgram.cc

index 80eaedbde2dafd0ab6f74b8350c28f768599587e..b2c2016f1968fe1b879a93cd3b17447a78b9edb6 100644 (file)
@@ -31,7 +31,7 @@ void makeReport(const struct pdns_timeval& tv)
   int64_t clientdiff = g_clientQuestions - g_clientResponses;
   int64_t serverdiff = g_serverQuestions - g_serverResponses;
 
-  if(clientdiff > 5 && clientdiff > 0.02*g_clientQuestions) {
+  if(clientdiff > 1 && clientdiff > 0.02*g_clientQuestions) {
     char tmp[80];
     struct tm tm=*pdns_localtime_r(&tv.tv_sec, &tm);
     strftime(tmp, sizeof(tmp) - 1, "%F %H:%M:%S", &tm);
@@ -50,7 +50,7 @@ void makeReport(const struct pdns_timeval& tv)
     cout<<"Last question: "<<tmp<<"."<<g_lastquestionTime.tv_usec/1000000.0<<endl;
   }
 
-  if(serverdiff > 5 && serverdiff > 0.02*g_serverQuestions) {
+  if(serverdiff > 1 && serverdiff > 0.02*g_serverQuestions) {
     char tmp[80];
     struct tm tm=*pdns_localtime_r(&tv.tv_sec, &tm);
     strftime(tmp, sizeof(tmp) - 1, "%F %H:%M:%S", &tm);
@@ -106,6 +106,8 @@ try
     
     map<pair<string, uint16_t>, int> counts;
 
+    map<double, int> rdqcounts, rdacounts;
+
     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) &&
@@ -118,6 +120,7 @@ try
           }
 
           if(mdp.d_header.rd && !mdp.d_header.qr) {
+           rdqcounts[pr.d_pheader.ts.tv_sec + 0.01*(pr.d_pheader.ts.tv_usec/10000)]++;
             g_lastquestionTime=pr.d_pheader.ts;
             g_clientQuestions++;
             totalQueries++;
@@ -125,6 +128,7 @@ try
             questions.insert(make_pair(mdp.d_qname, mdp.d_qtype));
           }
           else if(mdp.d_header.rd && mdp.d_header.qr) {
+           rdacounts[pr.d_pheader.ts.tv_sec + 0.01*(pr.d_pheader.ts.tv_usec/10000)]++;
             g_lastanswerTime=pr.d_pheader.ts;
             g_clientResponses++;
             answers.insert(make_pair(mdp.d_qname, mdp.d_qtype));
@@ -141,7 +145,7 @@ try
             g_serverResponses++;
           }
           
-          if(pr.d_pheader.ts.tv_sec - lastreport.tv_sec >= 5) {
+          if(pr.d_pheader.ts.tv_sec - lastreport.tv_sec >= 1) {
             makeReport(pr.d_pheader.ts);
             lastreport = pr.d_pheader.ts;
           }          
@@ -156,7 +160,22 @@ try
           continue;
         }
       }
+    }
+
+    map<double, pair<int, int>> splot;
+
+    for(auto& a : rdqcounts) {
+      splot[a.first].first = a.second;
+    }
+    for(auto& a : rdacounts) {
+      splot[a.first].second = a.second;
+    }
 
+    cerr<<"Writing out sub-second rd query/response stats to ./rdqaplot"<<endl;
+    ofstream plot("rdqaplot");
+    plot<<std::fixed;
+    for(auto& a : splot) {
+      plot << a.first<<"\t"<<a.second.first<<"\t"<<a.second.second<<endl;
     }
     cerr<<"Parse errors: "<<parseErrors<<", total queries: "<<totalQueries<<endl;
     typedef vector<queries_t::value_type> diff_t;