From: bert hubert Date: Sat, 21 Nov 2015 20:58:53 +0000 (+0100) Subject: add dumpStats() X-Git-Tag: dnsdist-1.0.0-alpha1~210^2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a817e5a30dd105859af21662c78fb9014625b14;p=pdns add dumpStats() --- diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index 649885b71..fd5bd5fce 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -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 diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 3a3945a68..7db5a4582 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -871,6 +871,49 @@ vector> 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 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(&e.second)) + second=std::to_string((*val)->load()); + else if (const auto& val = boost::get(&e.second)) + second=(flt % (**val)).str(); + else + second=std::to_string((*boost::get(&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)