]> granicus.if.org Git - pdns/commitdiff
add dumpStats()
authorbert hubert <bert.hubert@netherlabs.nl>
Sat, 21 Nov 2015 20:58:53 +0000 (21:58 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sat, 21 Nov 2015 20:59:45 +0000 (21:59 +0100)
pdns/README-dnsdist.md
pdns/dnsdist-lua.cc

index 649885b718ab91b1590063705a9a44045eab9b72..fd5bd5fce91d7b6a7f8d2fed775c214437650615 100644 (file)
@@ -556,6 +556,7 @@ Here are all functions:
    * `testCrypto()`: test of the crypto all works
    * `controlSocket(addr)`: open a control socket on this address / connect to this address in client mode
  * Diagnostics and statistics
+   * `dumpStats()`: print all statistics we gather
    * `topQueries(n[, labels])`: show top 'n' queries, as grouped when optionally cut down to 'labels' labels
    * `topResponses(n, kind[, labels])`: show top 'n' responses with RCODE=kind (0=NO Error, 2=ServFail, 3=ServFail), as grouped when optionally cut down to 'labels' labels
    * `showResponseLatency()`: show a plot of the response time latency distribution
index 3a3945a6812de137effb80936b556f3b7e02eacd..7db5a4582d67cf2a46c60b019b55a644f37cb916 100644 (file)
@@ -871,6 +871,49 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
   g_lua.writeFunction("setTCPRecvTimeout", [](int timeout) { g_tcpRecvTimeout=timeout; });
 
   g_lua.writeFunction("setTCPSendTimeout", [](int timeout) { g_tcpSendTimeout=timeout; });
+
+  g_lua.writeFunction("dumpStats", [] {
+      vector<string> leftcolumn, rightcolumn;
+
+      boost::format fmt("%-23s\t%+11s");
+      g_outputBuffer.clear();
+      auto entries = g_stats.entries;
+      sort(entries.begin(), entries.end(), 
+          [](const decltype(entries)::value_type& a, const decltype(entries)::value_type& b) {
+            return a.first < b.first;
+          });
+      boost::format flt("    %9.1f");
+      for(const auto& e : entries) {
+       string second;
+       if(const auto& val = boost::get<DNSDistStats::stat_t*>(&e.second))
+         second=std::to_string((*val)->load());
+       else if (const auto& val = boost::get<double*>(&e.second))
+         second=(flt % (**val)).str();
+       else
+         second=std::to_string((*boost::get<DNSDistStats::statfunction_t>(&e.second))(e.first));
+
+       if(leftcolumn.size() < g_stats.entries.size()/2)
+         leftcolumn.push_back((fmt % e.first % second).str());
+       else
+         rightcolumn.push_back((fmt % e.first % second).str());
+      }
+
+      auto leftiter=leftcolumn.begin(), rightiter=rightcolumn.begin();
+      boost::format clmn("%|0t|%1% %|39t|%2%\n");
+
+      for(;leftiter != leftcolumn.end() || rightiter != rightcolumn.end();) {
+       string lentry, rentry;
+       if(leftiter!= leftcolumn.end()) {
+         lentry = *leftiter;
+         leftiter++;
+       }
+       if(rightiter!= rightcolumn.end()) {
+         rentry = *rightiter;
+         rightiter++;
+       }
+       g_outputBuffer += (clmn % lentry % rentry).str();
+      }
+    });
   
   std::ifstream ifs(config);
   if(!ifs)